Excel VBA macrosHack 22
    data extraction
    excel lists
    file extensions
    Microsoft files

    How to List All File Names from a Folder into Excel (VBA)

    Excel Hack #22

    12 views
    2 min read
    2017-02-07
    How to List All File Names from a Folder into Excel (VBA)

    For one reason or the other, you may require the list of the names of all files in a particular folder on your system extracted out as text into Excel. Maybe you want all files with a particular exten...

    For one reason or the other, you may require the list of the names of all files in a particular folder on your system extracted out as text into Excel. Maybe you want all files with a particular extension, say .doc, or .html. The macro below will help you get this done under a minute:

     

    For one reason or the other, you may require the list of the names of all files in a particular folder on your system extracted out as text into Excel. Maybe you want all files with a particular extension, say .doc, or .html. The macro below will help you get this done under a minute:

    Sub ListFiles()

    F = Dir("C:Users\Name\Downloads Folder B\*.doc") 
    Do While Len(F) > 0
    ActiveCell.Formula = F
    ActiveCell.Offset(1, 0).Select
    F = Dir()
    Loop

    End Sub

    Sub ListFiles()
    
    Dim FileName as String
    
    FileName = Dir("C:Users\Name\Downloads Folder B\*.doc") 
    Do While Len(FileName) > 0
    ActiveCell.Formula = FileName
    ActiveCell.Offset(1, 0).Select
    FileName = Dir()
    Loop
    
    End Sub

    On Line 5, Change C:Users\Name\Downloads Folder B\ to the location of the folder you want to extract from (you can find this by right-clicking inside the folder, going to Properties and extracting what's in front of Location), and change .doc to the file extension you want to extract. Ensure you add the asterisk sign (*), as that is a wildcard operator to find all files within the folder that have the indicated file extension.

    Frequently Asked Questions