How to Recursively Search XLS Files Using VBScript
Question details
The user needs a VBScript or VBA solution to automatically search through multiple nested folders and locate specific content within multiple XLS files.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Attempting to locate specific data or text across a large number of XLS workbooks distributed across complex directory structures.
- Observed behavior
- The goal is to programmatically identify target files and extract or verify data without having to manually open each XLS file in the directory hierarchy.
Ensure that the Developer tab is enabled in your spreadsheet software and always create backup copies of your directories before running automated scripts to prevent unintended data loss.
Use a Custom FileSearch Class Module in VBA
Import a pre-written recursive file-search class module into your VBA editor to handle complex folder traversals safely and efficiently.
Since legacy file search objects have been deprecated in modern spreadsheet software, implementing a custom class module (like FileSearch.cls) is the most robust way to iterate over subfolders. This custom class encapsulates the recursive logic, making your main script much cleaner.
Obtain a reliable recursive file search class file, such as FileSearch.cls, which contains the predefined VBScript/VBA code for iterating through nested directories.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, right-click on your VBAProject, select 'Import File...', and browse to the FileSearch.cls file you downloaded.
Read the comments at the top of the imported class module for a usage example. Create a new standard module, paste the example code, set your target folder path, and execute the macro to search through the XLS files.

Run VBA Macros and Scripts Easily with WPS Spreadsheet
WPS Office provides robust support for running complex VBA macros and scripts, making it simple to execute recursive searches across multiple workbooks.
- 1. Launch WPS Spreadsheet: Open WPS Office and create a new blank spreadsheet to act as your macro control workbook.
- 2. Access Developer Tools: Click on the 'Developer' tab on the top ribbon. If you cannot see it, navigate to Menu > Options > Customize Ribbon to enable it.
- 3. Open the VBA Editor: Click the 'Visual Basic' icon or press Alt + F11 to launch the macro development environment.
- 4. Import and Execute: Right-click the project explorer, select 'Import File' to bring in your FileSearch.cls, paste your execution code into a new module, and click 'Run'.

Frequently Asked Questions
Why is Application.FileSearch failing in my script?
The Application.FileSearch object was deprecated and removed starting with Excel 2007. To perform recursive searches in modern versions, you must rely on custom VBA classes or the FileSystemObject (FSO).
Can I use FileSystemObject (FSO) for recursive folder searches?
Yes. FSO is a built-in library that can iterate through folders and subfolders. You can write a recursive function utilizing FSO's GetFolder and SubFolders methods to find XLS files.
How do I prevent my application from freezing during a long recursive search?
Insert the 'DoEvents' function inside your recursive loop. This command temporarily pauses the macro to allow the operating system to process other background events, keeping the software responsive.
Will this VBScript search inside password-protected XLS files?
No, standard VBScript searches cannot bypass password protection. If your macro attempts to open a password-protected workbook programmatically to check its contents, it will pause and prompt the user for the password unless it is provided in the VBA code.




