Hello andyrads,
Finding a file by name on any drive is something that comes up rather frequently. I decided to bite the bullet and write the code. This code makes use of the File System Object which is part of the Microsoft Scripting Runtime Library. This first appeared in Excel 2000. If your version of Excel is earlier than 2000, the code won't run.
The macro "FindFileNamed" has 2 arguments: the File Path and the File Name. The file path can be the root directory, like "C:\", a partial path which will check all sub directories, or a full path, or no path (an empty string). If no path is chosen then all local drives are checked. Successful search paths are saved in a Public Collection Object "PathsFound". The directory paths are available to all procedures because the object is public. The information only changes when the macro "FindFileNamed" is run.
Macro Code
Examples
Setting a Reference in VBA- Open your workbook and then press ALT+F11 to open the VBE.
- Press ALT+T followed by the Enter key.
- Scroll down the list until you find Microsoft Scripting Runtime Library.
- Press the Space bar to select it, and press Enter
- Press CTRL+S to save the reference in the project
Bookmarks