简体   繁体   中英

Excel VBA insert a hyperlink

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM