Application.FileSearch

Removed in Office 2007
Office 97 introduced a FileSearch object (enhanced in 2002) that allows you to search and maintain files easily.
This allows you to search for files with a wide range of search criteria such as file type, file size, file location and date of last modification.
This object can be found in the Office library.

The FileSearch object basically gives you all the functionality of the (File > Open) dialog box
You can use FileSearch instead of using the earlier Dir() function.


Types of Objects

FileTypes - In 97 and 2000 you could only specify a single FileType property. Office 2002 introduced a FileTypes collection that allows you to specify multiple file types.
FoundFiles collection - All the matching file names are placed in this collection.
PropertyTests -
SearchScopes collection - (Added 2002)
ScopeFolders - (Added 2002)
SearchFolders - (Added 2002)


Example


Key Properties and Methods

FileNamespecifies the name of the file to be found (wildcards can be used)
FoundFileReturns a FileSystem object that contains the names of the files that have been found
LookInSpecifies the directory to be searched
SearchSubFoldersReturns True if subdirectories are to searched
ExecutePerforms the search
NewSearchResets the FileSearch object to its default settings. All property values are retained after each search is run, and by using the NewSearch method you can selectively set properties for the next file search without manually resetting previous property values.

Any files found are placed in a FoundFiles collection


List all the files in the root directory


Return most recent file from a folder



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext