E
Ed
I'm trying to write a macro based on the FileSearchObject. I'm trying to do
the same thing as File>Open>Tools>Find. I will present an Input Box to the
user, asking for File Name and Text String search criteria, then use these
strings in the macro. I pulled the following code from the Help file for
the FileSearchObject, but it needs some tweaking:
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 WithWhere, and how, do I insert the text strings to search for? Also,
this code presents the names of all the found files in message boxes, one at
a time. If there's a zillion files meeting the criteria, I get a zillion
messages. How can I get a single list of all the file names?Thanks.Ed
the same thing as File>Open>Tools>Find. I will present an Input Box to the
user, asking for File Name and Text String search criteria, then use these
strings in the macro. I pulled the following code from the Help file for
the FileSearchObject, but it needs some tweaking:
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 WithWhere, and how, do I insert the text strings to search for? Also,
this code presents the names of all the found files in message boxes, one at
a time. If there's a zillion files meeting the criteria, I get a zillion
messages. How can I get a single list of all the file names?Thanks.Ed