kevin1010,
I created a macro that should accomplish what you're looking for. Some notes about the macro:- Change FldrCol to the column that contains the folder and file information (it was column A in the sample workook)
- Change StartRow to the row that the folder and file information starts on (it was row 3 in the sample workbook)
- Change the strBasePath to the base folder that contains the listed folders and subfolders. Be sure to include the ending \
Here's the code:
Sub CreateLinks()
Dim FldrCol As String: FldrCol = "A"
Dim StartRow As Long: StartRow = 3
Const strBasePath As String = "C:\Test Folder\" 'Be sure to include the ending \
Application.ScreenUpdating = False
Dim rngData As Range: Set rngData = ActiveSheet.Range(FldrCol & StartRow, Cells(Rows.Count, FldrCol).End(xlUp))
Dim aCell As Range, strTopFldr As String, strSubFldr As String, strFullPath As String
For Each aCell In rngData
If aCell.Interior.ColorIndex = 37 Then
strTopFldr = aCell.Value & "\"
ElseIf aCell.Font.Bold = True Then
strSubFldr = aCell.Value & "\"
Else
strFullPath = strBasePath & strTopFldr & strSubFldr
Dim FileFound As Boolean: FileFound = False
Dim CurrentFile As String: CurrentFile = Dir(strFullPath)
While CurrentFile <> vbNullString And FileFound = False
If InStr(1, CurrentFile, aCell.Value, vbTextCompare) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=aCell, _
Address:=strFullPath & CurrentFile, _
TextToDisplay:=aCell.Value
FileFound = True
End If
CurrentFile = Dir()
Wend
End If
Next aCell
Application.ScreenUpdating = True
End Sub
Hope that helps,
~tigeravatar
Bookmarks