Execute Method (FileSearch Object) Example
This example searches for all files in the My Documents folder that end with the file name extension “.doc” and then displays the location and name of each file found. The example also sorts the list of returned file names in ascending alphabetic order.
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "*.doc"
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) > 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