Excel VBA Find File in Folder and Subfolders

This post demonstrates how to find files in a folder and subfolders that match a user-entered search string.  The user is prompted to select a folder, then enters a search string (file name or partial file name).  The VBA code then searches each folder and subfolder to find any files that match the string.  Finally, a list of files is built in the Excel worksheet, with a hyperlink to each file the user can click on to open the respective file.

Setup – Excel VBA Find File in Folder and Subfolders

This code was written and tested in Excel 2013.

Insert a new module into your excel workbook, and add the following VBA code:

While in the module window, go to “Tools – References” and make sure the following are checked:

Excel VBA Find File in Folder and Subfolders

Now you are ready to run the macro!

In the “Developer” menu tab, select “Macros”

Excel VBA Find File in Folder and Subfolders

Select the “FindFile” macro and click “Run”

Excel VBA Find File in Folder and Subfolders

You will then be prompted to select a folder to start the search:

Excel VBA Find File in Folder and Subfolders

Select the folder and click “OK”

Next, you are prompted to enter a search string (either full or partial file name, excluding file type extension).  This is CASE-SENSITIVE!

Excel VBA Find File in Folder and Subfolders

Click “OK” and you will see search results like the following:

Excel VBA Find File in Folder and Subfolders

Notice the Hyperlinks in column B (Full path of file).  Go ahead and click on the Hyperlink for a given file, and the file will open:

Excel VBA Find File in Folder and Subfolders

I hope you find this post helpful.  Feel free to modify the code to suit your needs.  Enjoy!

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering  Qlikview  SQL Server  Excel VBA

 

 

2 thoughts on “Excel VBA Find File in Folder and Subfolders

    • I will likely make a new post for this, but want to clarify the question. Would you already have the listing of files and folders in Excel? Then you’d be looking to select a folder and create a hyperlink to files in the list in excel, where file names match exactly to PDF files in selected folder?

Leave a Comment