Reputation: 930
I'm developing an Excel macro with VBA to create add a hyperlink in a Word template. I've added a bookmark in the template, where the hyperlink should go, called "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
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. The bookmark name has the correct bookmark and the MyWebAdd variable has the correct web address
WrdApp.ActiveDocument.Bookmarks(BookMarkName).Select
WrdApp.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
WrdApp.Selection.TypeText MyWebAdd
Thanks for your help with this issue.....
Upvotes: 0
Views: 715
Reputation: 7860
The very first example in the online help shows you that the anchor needs to be a Range
not a string.
With WrdApp.ActiveDocument
.Hyperlinks.Add Anchor:=.Bookmarks(BookmarkName).Range, _
Address:=MyWebAdd, _
TextToDisplay:=MyWebAdd
End With
Upvotes: 1