Option Explicit
Private Const TargetRng = "B3:B74"
Private Const ParentPath = "[COLOR=#ff0000]C:\folder\subfolder[/COLOR]"
[I]
[COLOR=#006400]Private Sub Worksheet_Change(ByVal Target As Range)[/COLOR][/I]
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Range(TargetRng), Target) Is Nothing Then
Call OpenWorkbook(Target.Value)
End If
[I][COLOR=#006400]End Sub[/COLOR][/I]
[I][COLOR=#006400]
Private Function OpenWorkbook(SearchFor As String) As Workbook[/COLOR][/I]
Dim fPath As String: fPath = GetFilePath(ParentPath & Chr(92), SearchFor, ".xls", True)
If Len(fPath) > 0 Then
Set OpenWorkbook = Workbooks.Open(fPath)
MsgBox "Workbook found" & vbCr & vbCr & OpenWorkbook.FullName
Else
MsgBox SearchFor & " not found"
End If
[COLOR=#006400][I]End Function[/I][/COLOR]
[I][COLOR=#006400]
Private Function GetFilePath(ParentFolder As String, sTxt As String, Ext As String, SearchParent As Boolean) As String[/COLOR][/I]
Dim FSO As Object, Fldr, SubFldr, aFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fldr = FSO.GetFolder(ParentFolder)
[COLOR=#a52a2a]'SearchParentFolder[/COLOR]
If SearchParent Then
For Each aFile In Fldr.Files
If InStr(1, aFile.Name, sTxt & Ext, vbTextCompare) > 0 Then
GetFilePath = aFile.Path
Exit Function
End If
Next aFile
End If
[COLOR=#a52a2a]'SearchSubFolders[/COLOR]
For Each SubFldr In Fldr.SubFolders
For Each aFile In SubFldr.Files
If InStr(1, aFile.Name, sTxt, vbTextCompare) > 0 Then
GetFilePath = aFile.Path
Exit Function
End If
Next aFile
GetFilePath = GetFilePath(SubFldr.Path, sTxt, Ext, False)
Next SubFldr
GetFilePath = ""
[I][COLOR=#006400]End Function[/COLOR][/I]