Display All Files in Folder in Worksheet

How to display all files in folder in worksheet automatically using VBA. Lst time we learnt how to display all files in a folder in combo-box on a user-form using the FileSystemObject or FSO. The FileSystemobject allows us to access and manipulate files and folder on our computer system quickly and easily using VBA. Watch the video below:

Display All Files in Folder in Worksheet

Here’s the complete VBA code to get all the file names in a folder into a worksheet:

Sub getFilenamesFromFolder()
Dim fso As FileSystemObject, myfolder As Object, myfile As Object
Dim i As Long
i = 2
Range(“A1”) = “File Names”
Set myfso = New Scripting.FileSystemObject
Set myfolder = myfso.GetFolder(“c:\invoices”)

For Each myfile In myfolder.Files
Cells(i, 1) = myfile.Name
i = i + 1
Next myfile
End Sub