Results 1 to 2 of 2

Return files from a folder without Subfolder

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196

    Return files from a folder without Subfolder

    Hello! Long time since last post.

    I'm struggling with this code to list all the files from a specified folder. The code works great, but I'm trying to figure out what I need to alter to return only the names & file types, without having to see the subfolders. If I know that the files are in say G:, I don't want to see the path in front of all the file names.

    Function CreateFileList(FileFilter As String, _
        IncludeSubFolder As Boolean) As Variant
        Dim FileList() As String, FileCount As Long
        CreateFileList = ""
        Erase FileList
        If FileFilter = "" Then FileFilter = "*.*" 
        With Application.FileSearch
            .NewSearch
            .LookIn = "G:\mywork"
            .FileName = FileFilter
            .SearchSubFolders = False
            .FileType = msoFileTypeAllFiles
            If .Execute(SortBy:=msoSortByFileName, _
            SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
            ReDim FileList(.FoundFiles.Count)
            For FileCount = 1 To .FoundFiles.Count
                FileList(FileCount) = .FoundFiles(FileCount)
            Next FileCount
            .FileType = msoFileTypeExcelWorkbooks 
        End With
        CreateFileList = FileList
        Erase FileList
    End Function
     
    Sub TestCreateList()
        Dim FileNamesList As Variant, i As Integer
        FileNamesList = CreateFileList("*.*", False)
        Range("A:A").ClearContents
        Range("A1").Select
        Selection.Font.Bold = True
        Selection.Font.Underline = xlUnderlineStyleSingle
        ActiveCell.FormulaR1C1 = "Files"
        Range("H1").Select
        For i = 1 To UBound(FileNamesList)
            Cells(i + 1, 1).Formula = FileNamesList(i)
        Next i
    End Sub
    Thanks for the help
    Last edited by EMoe; 02-24-2009 at 01:44 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1