FileSearch Object

FileSearch
Multiple objects

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 files and displays the number of files found and the name of each 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 | FileTypes Property | FoundFiles Property | LastModified Property | LookIn Property | MatchAllWordForms Property | MatchTextExactly Property | PropertyTests Property | SearchFolders Property | SearchScopes Property | SearchSubFolders Property | TextOrProperty Property

Methods | Execute Method | NewSearch Method | RefreshScopes Method

Parent Objects

Child Objects | FileTypes Object | FoundFiles Object | PropertyTests Object | SearchFolders Object | SearchScopes Object

See Also | FileTypes Collection | FoundFiles Property | PropertyTest Object | PropertyTests Property | ScopeFolder Object | ScopeFolders Collection | SearchFolders Collection | SearchScope Object | SearchScopes Collection