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

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.