Add hyperlink into Word Content Control with VBA -
Add hyperlink into Word Content Control with VBA -
i have word 2010 template. when used, form presented user , prompted come in string in textbox named bugnumtextbox. upon command, wish build url, create hyperlink, , insert document.
the desired insertion point (anchor) rich text content command tag name of "foo". address parameter have attempted:
1) specify range of content control 2) specify range of bookmark (named bugnum) created within of content control.
neither have worked, resulting in run-time errors. can suggest method accomplish this? below non-working illustration of method 2 above.
activedocument.hyperlinks.add anchor:=.bookmark("bugnum").range, address:= _ "http://bugs.fubar.net/show_bug.cgi?id=" & bugnumtextbox, _ subaddress:="", screentip:="", texttodisplay:=""
thank much.
why don't access contentcontrols object collection instead. like:
dim ccrtxt contentcontrol set ccrtxt = activedocument.contentcontrols(1) ccrtxt.range.hyperlinks.add ccrtxt.range, _ "http://stackoverflow.com/questions/26538906/" & _ "add-hyperlink-into-word-content-control-with-vba"
above work on scenario describe have 1 contentcontrol. if have many such objects, can this:
dim ccrtxt contentcontrol each ccrtxt in activedocument.contentcontrols if ccrtxt.tag = "foo" ccrtxt.range.hyperlinks.add ccrtxt.range, _ "http://stackoverflow.com/questions/26538906/" & _ "add-hyperlink-into-word-content-control-with-vba" end if next
this adds question hyperlink address in rich text content control. can adjust address property suit needs. hth.
vba ms-word
Comments
Post a Comment