E
Ed
I'm reposting this because I've managed (somehow!) to make some significant
progress (thank you, Malcolm!). In a nutshell, I'm trying to mimic the
File>Open>Tools>Find function that will enable my users to search through
about 8,000 documents by specifying document title and text string criteria.
The search part of the code is at the bottom of the post.
I've got the code to constrain to title criteria and ONE text string. I can
't get the multiple text strings, though. I've tried several different
ways. My best guesses were:
.TextOrProperty = strText1, strText2, strText3, strText4
.TextOrProperty = strText1 & strText2 & strText3 & strText4
but nothing works. The first one errors out, and the second returns nothing
if I have more than one criteria entered.
Any help getting multiple text string search criteria to work will be
greatly appreciated.
Ed
Sub TestFileSearch()
Dim strName As String
Dim strText1 As String
Dim strText2 As String
Dim strText3 As String
Dim strText4 As String
' Limit to one set?
strName = InputBox("If you want to constrain your search to one set, please
type the letter corresponding to that set. Otherwise, leave blank to search
all sets.", "One or all sets?")
' Enter text strings to search for
MsgBox "You may enter up to four text strings as search criteria. You may
enter phrases of more than one word. Strings may contain wildcards (* or
?)."
strText1 = InputBox("Enter your first search criteria.", "Text String 1")
strText2 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 2")
strText3 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 3")
strText4 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 4")
' Start search
With Application.FileSearch
.NewSearch
' Set primary folder to search.
.LookIn = "C:\My Search Folder"
' Search sub folders of primary search folder.
.SearchSubFolders = True
' Search for only these documents.
.FileName = "L5-" & strName & "*.doc"
' Search for these text strings
.TextOrProperty = strText1 & strText2 & strText3 & strText4
.FileType = msoFileTypeWordDocuments
' Execute search.
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
' More code follows to deal with results
progress (thank you, Malcolm!). In a nutshell, I'm trying to mimic the
File>Open>Tools>Find function that will enable my users to search through
about 8,000 documents by specifying document title and text string criteria.
The search part of the code is at the bottom of the post.
I've got the code to constrain to title criteria and ONE text string. I can
't get the multiple text strings, though. I've tried several different
ways. My best guesses were:
.TextOrProperty = strText1, strText2, strText3, strText4
.TextOrProperty = strText1 & strText2 & strText3 & strText4
but nothing works. The first one errors out, and the second returns nothing
if I have more than one criteria entered.
Any help getting multiple text string search criteria to work will be
greatly appreciated.
Ed
Sub TestFileSearch()
Dim strName As String
Dim strText1 As String
Dim strText2 As String
Dim strText3 As String
Dim strText4 As String
' Limit to one set?
strName = InputBox("If you want to constrain your search to one set, please
type the letter corresponding to that set. Otherwise, leave blank to search
all sets.", "One or all sets?")
' Enter text strings to search for
MsgBox "You may enter up to four text strings as search criteria. You may
enter phrases of more than one word. Strings may contain wildcards (* or
?)."
strText1 = InputBox("Enter your first search criteria.", "Text String 1")
strText2 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 2")
strText3 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 3")
strText4 = InputBox("Enter your next search criteria. If none, leave
blank", "Text String 4")
' Start search
With Application.FileSearch
.NewSearch
' Set primary folder to search.
.LookIn = "C:\My Search Folder"
' Search sub folders of primary search folder.
.SearchSubFolders = True
' Search for only these documents.
.FileName = "L5-" & strName & "*.doc"
' Search for these text strings
.TextOrProperty = strText1 & strText2 & strText3 & strText4
.FileType = msoFileTypeWordDocuments
' Execute search.
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
' More code follows to deal with results