Hi,
this code gathers file location and file names and the output is starting in A3.
I would like to, either
1- have a hyperlink to the respective file in cell B3, B4, etc. or
2- have the searchresult itself, so A3, A4, etc. be the hyperlink
I would prefer option 1 and if possible have the hyperlink text be something like <Get File>.
Thanks for your help.
Stefan
Sub search1()
Dim Message1, Title1, MyValue1
Dim Message2, Title2, MyValue2
Dim Message3, Title3, MyValue3, MyFolder
Range("A:A").ClearContents
Title3 = "Select Search Location"
Message3 = "Perform the search through ..." & Chr(10) & Chr(10) & _
"1 = ... all Service Forms" & Chr(10) & _
"2 = ... only Completed Service Forms" & Chr(10) & _
"3 = ... only Pending Service Forms" & Chr(10)
MyValue3 = InputBox(Message3, Title3)
MyFolder = "C:\_stefan's"
If MyValue3 = "2" Then MyFolder = "C:\_stefan's\_pend"
If MyValue3 = "3" Then MyFolder = "C:\_stefan's\_comp"
'End If
With Application.FileSearch
.NewSearch
.LookIn = MyFolder
.SearchSubFolders = True
Title1 = "Enter Search Term 1"
Title2 = "Enter Search Term 2"
Message1 = "This will perform a search for Service Form files." & Chr(10) & Chr(10) & _
"You may enter any 'string', i.e. Consultant ID." & Chr(10) & _
"The output will show the file(s) location, i.e. L:\Consultant Services\Returns\Service_Form\" & Chr(10) & _
"and the respective file name(s)." & Chr(10)
Message2 = "This will add a search within the file(s)" & Chr(10) & _
"and can contain wildcards like '*'." & Chr(10) & Chr(10) & _
"The result(R) has to match the search(S) term exactly." & Chr(10) & _
"I.e. (S)=Credit or (S)=Cred* will return all files containing (R)Credit whereas (S)=Cred will not be found." & Chr(10)
MyValue1 = InputBox(Message1, Title1)
If MyValue1 = "" Then
MsgBox "You have to enter a search term/string.", vbCritical, "No Search Term - Error"
Exit Sub
End If
MyValue2 = InputBox(Message2, Title2)
If MyValue2 = "" Then MyValue2 = ""
.Filename = MyValue1
.TextOrProperty = MyValue2
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
Range("a3").Select
For i = 1 To .FoundFiles.Count
ActiveCell.FormulaR1C1 = .FoundFiles(i)
ActiveCell.Offset(1, 0).Select
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
Display More