Question

I have been trying to get a macro insert a dynamic hyperlink for a couple hours now and cannot seem to get the syntax correct.

I need to make my macro insert a hyperlink into rLinkCell that points to rTargetCell in shTargetSheet, use the label or display text stLinkName and have the Screen tip stTip.

I have gotten this far:

shCurSheet.Hyperlinks.Add Anchor:=rLinkCell, _
           Address:="", _
           SubAddress:=shTargetSheet.Name & "!" & rTargetCell.Address, _
           ScreenTip:=stTip, _
           TextToDisplay:=stLinkName

It makes the link perfectly and all the displays are fine, however when I click it I get an error saying Refrence is not valid.

I am certain it is something simple, what am I doing wrong?

Was it helpful?

Solution

If all you want to do is create a hyperlink on a sheet, you can just use the =HYPERLINK() function.

I've just create an example workbook, here's the formula solution: https://spreadgit.com/bjoern/hyperlink-example.xlsb/sheets/Sheet1

and here's the VBA solution: https://spreadgit.com/bjoern/hyperlink-example.xlsb/modules/Module1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top