0
votes

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.....

1
Did you look up the online help article? The very first example shows you what you need to do.Timothy Rylatt
@TimothyRylatt............I did look at that article several times. I tried to adapt the bookmark example (#2) to my situation. Example #1 doesn't deal with a bookmark so I didn't use it. I need the hyperlink in a specific place in the Word document. Thanks for your suggestion...Shaves

1 Answers

1
votes

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