Dear all;,
I just happened to need a file search method that also looks in sub-folders and discovered that the Application.FileSearch capability (that existed in 2003) has been depreciated in Excel 2007. I have therefore written a class object that mimics the old FileSearch capabilities (tried to make an exact copy).
The full workbook containing the class code as well as an example is attached
The code to use the class object is also shown below
It is pretty much a copy of the original Excel solution (or at least close). I have added a Verbose option which you can set to Silent, Errors only or Debug (including informational messages).![]()
Public Sub TestFileSearch() '# declare Dim FileSearch As New ollieFileSearch Dim FoundFile As Variant '# configure and execte With FileSearch .NewSearch .LookIn = "C:\TEMP" .SearchSubFolders = True .FileName = "*.xl*" .Verbose = oeErrors .Execute End With '# loop for files found For Each FoundFile In FileSearch.FoundFiles Debug.Print FoundFile Next FoundFile '# show count Debug.Print FileSearch.FoundFiles.Count End Sub
I hope you find this a useful utility and please feel free to copy it /change it etc etc!
Bookmarks