简体   繁体   English

Excel VBA插入超链接

[英]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 . 我需要使宏在rLinkCell中插入指向rTargetCell中的shTargetSheet的超链接,使用标签或显示文本stLinkName并具有屏幕提示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 . 它使链接完美,并且所有显示都很好,但是当我单击它时,我收到一条错误消息,指出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. 如果您要做的只是在工作表上创建超链接,则只需使用= HYPERLINK()函数。

I've just create an example workbook, here's the formula solution: https://spreadgit.com/bjoern/hyperlink-example.xlsb/sheets/Sheet1 我刚刚创建了一个示例工作簿,这是公式解决方案: https : //spreadgit.com/bjoern/hyperlink-example.xlsb/sheets/Sheet1

and here's the VBA solution: https://spreadgit.com/bjoern/hyperlink-example.xlsb/modules/Module1 这是VBA解决方案: https : //spreadgit.com/bjoern/hyperlink-example.xlsb/modules/Module1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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