How to hyperlink a local file location VBA

Viewed 13552

I am attempting to link a local file location to a already set excel cell. The link is saved into a local varible. I am having a issue hyperlinking the file adress.

ActiveCell.Hyperlinks.Add(Q:\Personnel\Read\QTF Employees\Active\testname.QTF.ptf)
3 Answers

This should do the trick.

With ActiveCell
  .Hyperlinks.Add Anchor:=.Range(ActiveCell.Address), _
  Address:="file:///Q:\Personnel\Read\QTF Employees\Active\testname.QTF.ptf", _
  TextToDisplay:="Test"
End With

I figured out you need to replace Anchor:=.Range(ActiveCell.Address) with Anchor:=.Range(Range("A1").Address) in order to prevent the wrong cell will be linked.

The problem with incorrectly placed hyperlinks can be solved easier: it seems there's no need to specify Anchor:= value. Check this link. So, using @DaBeau96 answer your code could simply look like this (tested on Excel 2016):

With ActiveCell
  .Hyperlinks.Add Address:="file:///Q:\Personnel\Read\QTF Employees\Active\testname.QTF.ptf", _
  TextToDisplay:="Test"
End With

Presumably MSDN and VBA's hints are incorrect because, according to them, .Hyperlinks.Add method requires Anchor:= argument.

Related