Discussion:
How to Create A hyperlink in a word document using VB.Net
(too old to reply)
Ben Reese
2007-04-03 16:18:04 UTC
Permalink
Hello

I need to programatically add hyperlinks to a word document, But I cant work
out the proper syntax.

I am using A VB.Net 2005 Program with a reference to
Microsoft.Office.Interop.Word

I am able to locate the range for which I want to add the hyperlink but I
don't know what parameters I should pass into Document.Hyperlinks.Add,
Particularly the Anchor parameter, passing the range From My cell doesnt work:
MyDocument.Hyperlinks.Add(MyCell.Range, "MyURL")

I have created a VBA macro in Word and the syntax is this, But I cant
translate it into anytjing .net will understand:
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="URL", _
SubAddress:="", ScreenTip:="", TextToDisplay:="Link"

This article doesnt make sense at all..
http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.word.hyperlinks.add(VS.80).aspx

Thanks. Confused :~

Ben
Ben Reese
2007-04-04 10:14:06 UTC
Permalink
I've solved it.

A classic case of it being much easier tomorow morning. Cell.Range is the
right thing. Not shure why it didn't seem to woork yesterday! Maybee its that
dasterdly Tuesday bug again :*)

My final statement that does what I want looks like this:

Dim _Hyperlink As Word.Hyperlink = _Document.Hyperlinks.Add(_Cell.Range,
URL, , URL, _Text)

Easy!
Post by Ben Reese
Hello
I need to programatically add hyperlinks to a word document, But I cant work
out the proper syntax.
I am using A VB.Net 2005 Program with a reference to
Microsoft.Office.Interop.Word
I am able to locate the range for which I want to add the hyperlink but I
don't know what parameters I should pass into Document.Hyperlinks.Add,
MyDocument.Hyperlinks.Add(MyCell.Range, "MyURL")
I have created a VBA macro in Word and the syntax is this, But I cant
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="URL", _
SubAddress:="", ScreenTip:="", TextToDisplay:="Link"
This article doesnt make sense at all...
http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.word.hyperlinks.add(VS.80).aspx
Thanks. Confused :~
Ben
Loading...