Using Advanced File-Searching Features

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You get programmatic access to the advanced features of the FileSearch object by using its PropertyTests collection. These features correspond to the options available in the Advanced Find dialog box, which is available through the Office File Open dialog box.

The Advanced Find Dialog Box

Aa141366.00601(en-us,office.10).gif

The PropertyTests collection contains the criteria for a file search. Some of these criteria might have been specified by properties of the FileSearch object itself while others must be added to the PropertyTests collection by using its Add method.

In the following example, one of the file-search criteria added to the PropertyTests collection corresponds to the Contents setting in the Property box and another corresponds to the includes words setting in the Condition box in the preceding figure.

Set fsoFileSearch = Application.FileSearch
With fsoFileSearch
   .NewSearch
   .FileName = strFileName
   .LookIn = strLookIn
   .SearchSubFolders = blnSearchSubDir
   .PropertyTests.Add "Contents", msoConditionIncludes, strFindThisText
   If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
      For Each varFile In .FoundFiles
         cboFoundCombo.AddItem varFile
      Next varFile
   Else
      cboFoundCombo.AddItem "No Matching Files Located!"
   End If
   cboFoundCombo.ListIndex = 0
End With

See Also

Working with Shared Office Components | Working with the FileSearch Object | The Basics of File Searching | Creating Reusable File-Search Code