I am trying to set up a file search in code using the FileSearch method (see code below). The problem I am having is this... I have a bunch of folders starting with "My", such as "My Documents", "My PDFs", etc. I want to search all of these folders at the same time however it seems that the .LookIn property doesn't support wildcards as the .FileName does. I tried setting the .LookIn to "C:\My*" but it doesn't work. I can get what I want by just setting .LookIn to "C:\" but the search then takes way too long. Can anyone help?
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "SomeFile.ext"
.SearchSubFolders = True
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
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "SomeFile.ext"
.SearchSubFolders = True
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