Public serchstr As String
Public notacces As String
Public serchindex As Long
Function Recurse(spath As String, inarr As Variant) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Dim txtp As String
On Error Resume Next
Err.Clear
Set myFolder = FSO.GetFolder(spath)
If Err.Number <> 0 Then
notacces = notaccess & spath & ", "
End If
For Each myFile In myFolder.Files
If (myFile.Name) = serchstr Then
newf = myFile.Path
MsgBox (newf)
With Worksheets(1)
.Hyperlinks.Add Anchor:=.Range(Cells(serchindex, 4), Cells(serchindex, 4)), _
Address:=newf, _
ScreenTip:="Whatever you want", _
TextToDisplay:=myFile.Name
End With
End If
Next
For Each mySubFolder In myFolder.SubFolders
Skip = False
If Not (Skip) Then
On Error Resume Next
Err.Clear
For Each myFile In mySubFolder.Files
If (myFile.Name) = serchstr Then
With Worksheets(1)
.Hyperlinks.Add Anchor:=.Range(Cells(serchindex, 4), Cells(serchindex, 4)), _
Address:=newf, _
ScreenTip:="Whatever you want", _
TextToDisplay:="myfile.name"
End With
End If
Next
Recurse = Recurse(mySubFolder.Path, inarr)
End If
conti:
Next
End Function
Sub callserch()
' change this index loop *** required
For i = 1 To 3
serchindex = i
serchstr = Cells(i, 3)
Dim spath As String
Dim pathn As String
Dim inarr As Variant
Dim cnt As Long
' change this to the path that you require
pathn = ActiveWorkbook.Path
spath = pathn
Call Recurse(spath, inarr)
Next i
End Sub