0

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?

1
  • Please post the rest of your code, or at least a minimum example (where you declare and assign your variables) so that we can attempt to resolve the problem. I think you need to be doing this to the Address property, not the SubAddress property. Commented May 12, 2014 at 19:05

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.