Question : What is the code to link a cell to a file?

I would like to link a cell to an external pdf file using a macro.
Please advise the best code for this
Thanks
Des

Answer : What is the code to link a cell to a file?

This should work... you need to specify the anchor value properly
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Sub doHyperLink()
 
Dim sPDFName As String
Dim sPDFPath As String
Dim XPath As String
Dim lastRowL As Integer
    
With Sheets("Ledger")
lastRowL = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
 
sPDFName = Sheets("Invoice").Range("B18").Value & " " & Sheets("Invoice").Range("J2").Value & " " & Now & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator & "\" & "Invoice"
Sheets("Ledger").Range("L1").Value = sPDFName
Sheets("Ledger").Range("L1").Replace What:=":", Replacement:="_", lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Sheets("Ledger").Range("L1").Replace What:="/", Replacement:="_", lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
  
XPath = sPDFPath & "\" & Sheets("Ledger").Range("L1")
 
Sheets("Ledger").Hyperlinks.Add Sheets("Ledger").Cells(lastRowL, 2), Address:=XPath
 
End Sub
Random Solutions  
 
programming4us programming4us