FileSearch Object

Description

Represents the functionality of the Open dialog box (File menu).

Using the FileSearch Object

Use the FileSearch property to return the FileSearch object. The following example searches for the specified files and displays both the number of files found and the title of each found file.

With Application.FileSearch
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With
Use the NewSearch method to reset the search criteria to the 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. The following example resets the search criteria to the default settings before beginning a new search.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .FileName = "Run"
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
End With
Properties

Application property, Creator property, FileName property, FileType property, FoundFiles property, LastModified property, LookIn property, MatchAllWordForms property, MatchTextExactly property, PropertyTests property, SearchSubFolders property, TextOrProperty property.

Methods

Execute method (FileSearch and FileFind objects), NewSearch method.