Display List of All Files in Folder in Combo Box

How to display a list of all files in a folder in a combo box on user-form with VBA. We will use the ‘FileSystemObject‘ or FSO. By creating an instance of the FileSystemObject in Excel VBA, we can access files and folders on our computer system. We are now able to manipulate the files like reading, deleting or looping through them. We can also perform the following actions using the FileSystemObject (FSO):

  1. We can check for the existence of the file or folder
  2. We can copy files from one folder to another
  3. We can create new folders
  4. We can rename the files and folders
  5. We can get the list of all files in a folder or sub-folder

How to enable the FileSystemObject quickly and easily: Go to Tools in the Visual Basic Editor and set the reference to the ‘Microsoft Scripting Runtime’. Watch the video below to learn more:

Display List of All Files in folder in Combo Box

Watch the video on YouTube.

Here’s the complete VBA code to show all the files in a folder in a combo-box on a user-form.

Private Sub UserForm_Initialize()
Dim myfso As FileSystemObject, myfolder As Object, myfile As Object


Set myfso = New Scripting.FileSystemObject
Set myfolder = myfso.GetFolder(“C:\invoices”)

For Each myfile In myfolder.Files
Me.ComboBox1.AddItem myfile.Name
Next myfile

End Sub