[英]Using Excel VBA to insert a hyperlink at a Word bookmark
I'm developing an Excel macro with VBA to create add a hyperlink in a Word template.我正在使用 VBA 开发 Excel 宏,以在 Word 模板中创建添加超链接。 I've added a bookmark in the template, where the hyperlink should go, called "WebAdd".
我在模板中添加了一个书签,其中超链接应为 go,称为“WebAdd”。 I've tried using the code below and am getting a Type Mismatch error.
我尝试使用下面的代码并收到类型不匹配错误。 Any suggestions would be greatly appreciated...
任何建议将不胜感激...
"MyWebAdd" is the web address for the hyperlink “MyWebAdd”是超链接的 web 地址
WrdApp.ActiveDocument.Hyperlinks.Add Anchor:=MyWebAdd, Address:="", SubAddress:="WebAdd", ScreenTip:="", TextToDisplay:=MyWebAdd
I've also used the following code.我还使用了以下代码。 It puts the web address at the bookmark but it is not a hyperlink a user can click on.
它将 web 地址放在书签中,但它不是用户可以单击的超链接。 The bookmark name has the correct bookmark and the MyWebAdd variable has the correct web address
书签名称具有正确的书签并且 MyWebAdd 变量具有正确的 web 地址
WrdApp.ActiveDocument.Bookmarks(BookMarkName).Select
WrdApp.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
WrdApp.Selection.TypeText MyWebAdd
Thanks for your help with this issue.....感谢您对这个问题的帮助......
The very first example in the online help shows you that the anchor needs to be a Range
not a string.在线帮助中的第一个示例向您展示了锚点必须是
Range
而不是字符串。
With WrdApp.ActiveDocument
.Hyperlinks.Add Anchor:=.Bookmarks(BookmarkName).Range, _
Address:=MyWebAdd, _
TextToDisplay:=MyWebAdd
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.