Excel VBA Search for Files in Folder and Subfolders

This post details a VBA macro to search for files based on an search string, then lists all files that have a partial match in the file name.  The macro will search a specified folder (user prompted to select base folder), and will then loop through and search each subfolder until all have been examined.

The end result of this macro is the creation of a table in the Excel file, which captures the following information about each file in the chosen root folder:

Name / Path / Size (KB) / DateLastModified / Attributes / DateCreated / DateLastAccessed / Drive / ParentFolder / ShortName / ShortPath / Type

Version of Excel:  2013

OS:  Windows 10

Excel VBA References for Project:  See end of post

Setup – Excel VBA Search for Files in Folder and Subfolders

Here is the code:

In Excel, setup a button object, then add the following code to the button on click event:

Your button should look like this:

Excel VBA Search for Files in Folder and Subfolders

Click the search button, and you will first be prompted to select a base folder to search:

Excel VBA Search for Files in Folder and Subfolders

Once folder is selected the macro prompts user to input a search string.  This can be a partial string and is case sensitive:

Excel VBA Search for Files in Folder and Subfolders

Following the search, your results should look like the following:

Excel VBA Search for Files in Folder and Subfolders

Please modify the macro to suit your specific needs.  If you have any input or questions, please post a comment below.

Enjoy!

 

Excel VBA Search for Files in Folder and Subfolders

 

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering Qlikview SQL Server Excel VBA

 

 

Leave a Comment