Results 1 to 4 of 4

Thread: Search Directories to List Files VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    15
    You can also use the filedialog method.

    Code:
    Function GetFolder(strPath As String) As String
        Dim fldr As FileDialog
        Dim sItem As String
        Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
        With fldr
            .Title = "Select a Folder"
            .AllowMultiSelect = False
            .InitialFileName = strPath
            If .Show <> -1 Then GoTo NextCode
            sItem = .SelectedItems(1)
        End With
    NextCode:
        GetFolder = sItem
        Set fldr = Nothing
    End Function
    where

    FileSpec = TextfilePath.Text & "\*.XLS"

    Code:
    Function GetFileList(FileSpec As String, FileArray() As Variant) As Variant
        Dim FileCount As Integer
        Dim FileName As String
        On Error GoTo NoFilesFound
        FileCount = 0
        FileName = Dir(FileSpec)
        If FileName = "" Then GoTo NoFilesFound
    '   Loop until no more matching files are found
        Do While FileName <> ""
            FileCount = FileCount + 1
            ReDim Preserve FileArray(1 To FileCount)
            FileArray(FileCount) = FileName
            FileName = Dir()
        Loop
        GetFileList = FileArray
        Exit Function
    '   Error handler
    NoFilesFound:
        GetFileList = False
    End Function
    Last edited by Rasm; 10-28-2011 at 06:18 AM.
    xl2007 - Windows 7
    xl hates the 255 number

Similar Threads

  1. Search and remove values ​​from a list
    By PcMax in forum Excel Help
    Replies: 4
    Last Post: 04-14-2013, 08:39 PM
  2. List of files in chronological order
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 11-12-2012, 10:16 PM
  3. VBA Function to Search in Array
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-10-2012, 11:34 AM
  4. Get Name List of All Open Workbook Files
    By princ_wns in forum Excel Help
    Replies: 5
    Last Post: 04-07-2012, 12:18 PM
  5. List Of All Files In A Folder
    By Excel Fox in forum Excel Help
    Replies: 2
    Last Post: 10-27-2011, 09:10 AM

Tags for this Thread

Posting Permissions

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