Inserting hyperlinks in a Word Document with vb.net

How to hyperlink sections of an open word document

Page 1 of 1

1 Replies - 5184 Views - Last Post: 18 April 2009 - 01:30 PM Rate Topic: -----

#1 SJNB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 09

Inserting hyperlinks in a Word Document with vb.net

Posted 18 April 2009 - 07:28 AM

I have a word document [adoc] with multiple occurrences of a particular word. One of the references [the one in the paragraph explaining what the the reference means] is book marked . I want to hyperlink other occurrences of the same reference using the book mark as the address [subaddress] to jump to.

I had no problems in VB6 but can't seem to crack it in .Net

Some code:
	 Dim M As Object = Nothing
	 Dim Ank As String = WordApp.Application.Selection.Text
	 Dim SA As String = adoc.Bookmarks.Item(1).Range.Text


The following throws an invalid parameter error
	 adoc.Hyperlinks.Add(Anchor:=Ank, Address:=M, SubAddress:=SA, ScreenTip:=M, TextToDisplay:=M, Target:=M)


Setting the optional parameters to nothing (M), " " or System.Reflection.Missing.Value does not seem to help


Any one got some experience to share?

Thanks in Advance :rolleyes:

Steve

Moderator Note: Added code tags. Please, use code tags when posting code: :code:
- Core


Is This A Good Question/Topic? 0
  • +

Replies To: Inserting hyperlinks in a Word Document with vb.net

#2 SJNB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 09

Re: Inserting hyperlinks in a Word Document with vb.net

Posted 18 April 2009 - 01:30 PM

View PostSJNB, on 18 Apr, 2009 - 06:28 AM, said:

I have a word document [adoc] with multiple occurrences of a particular word. One of the references [the one in the paragraph explaining what the the reference means] is book marked . I want to hyperlink other occurrences of the same reference using the book mark as the address [subaddress] to jump to.

I had no problems in VB6 but can't seem to crack it in .Net

Some code:
	 Dim M As Object = Nothing
	 Dim Ank As String = WordApp.Application.Selection.Text
	 Dim SA As String = adoc.Bookmarks.Item(1).Range.Text


The following throws an invalid parameter error
	 adoc.Hyperlinks.Add(Anchor:=Ank, Address:=M, SubAddress:=SA, ScreenTip:=M, TextToDisplay:=M, Target:=M)


Setting the optional parameters to nothing (M), " " or System.Reflection.Missing.Value does not seem to help


Any one got some experience to share?

Thanks in Advance :rolleyes:

Steve

Moderator Note: Added code tags. Please, use code tags when posting code: :code:
- Core


Sorted this one out in the wee small hours - I really stuffed up my initial effort - just goes to show how slow I can be - for interest it works for me if I do this

Dim M As Object = Nothing
Dim BM As Word.Bookmark = adoc.Bookmarks.Item(i)
adoc.Hyperlinks.Add(Anchor:=WordApp.Application.Selection.Range, Address:=M, SubAddress:=BM.Name.ToString, ScreenTip:=M, TextToDisplay:=M, Target:=M)




For some reason the Anchor:= parameter had to be the full object ie when I tried Dim WAS as Object = Wordapp.Application.Selection and set anchor:=WAS.Range it would not recognise Range as being a property. Beats me I'm an oops newbee - something about ByVal and ByRef or initalising objects maybe??
:w00t:
Core - No worries -Thanks ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1