How to Create Hyperlinks in multiple cells using EXcel VBA
How to Link Cells to Files/Folders using Excel VBA
There are many cases where we want to have a Hyperlink on a cell that opens a document / image etc.
In the following snippet we can see how that works
The sheet is the Master Sheet, which contains the list of Products that are compared. The comparison reports for these products are placed in separate files in the same folder.
The hyperlink uses Relative path - you can hardcode this to any particular folder
Dim i1 As Integer
Dim sA, sB As String
For i1 = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
If LenB(Trim$(Cells(i1, 3).Value)) <> 0 Then
sA = Trim$(Cells(i1, 1).Value)
sB = Trim$(Cells(i1, 2).Value)
sA = "Compared_" & sA & "_" & sB & ".xls"
Sheets(1).Range("C" & i1).Hyperlinks.Add Cells(i1, 3), "CompareReports\" & sA
See also: Convert URLs to Hyperlinks using VBA