Hyperlinks and Colours

J

Jenny Fletcher

I have two questions regarding the Word 9 Object library.

1. In my word document I have a contents section where the
entries are linked to the corresponding sections in the
document. In my code I am trying to determine the Range
that the hyperlinks are linked to.

e.g.

Dim objHyperlink As Word.Hyperlink
Dim objWdRange as Word.Range
Dim strName as Name

'check for hyperlinks
If objWdRange.Hyperlinks.Count > 0 Then
For Each objHyperlink In WdRange.Hyperlinks
'check that the hyperlink is within range
If objHyperlink.Range.Start >= objWdRange.Start And
objHyperlink.Range.End < objWdRange.End Then
strName = objHyperlink.Name
'which range does this hyperlink link to ????

End If
Next
End If

2. Also, how do I make translate the Word colour constants
into something that I can make any sense of in VB.NET?

Thanks for any help,

Jenny
 
J

Jonathan West

Hi Jenny

Jenny Fletcher said:
I have two questions regarding the Word 9 Object library.

1. In my word document I have a contents section where the
entries are linked to the corresponding sections in the
document. In my code I am trying to determine the Range
that the hyperlinks are linked to.

e.g.

Dim objHyperlink As Word.Hyperlink
Dim objWdRange as Word.Range
Dim strName as Name

'check for hyperlinks
If objWdRange.Hyperlinks.Count > 0 Then
For Each objHyperlink In WdRange.Hyperlinks
'check that the hyperlink is within range
If objHyperlink.Range.Start >= objWdRange.Start And
objHyperlink.Range.End < objWdRange.End Then
strName = objHyperlink.Name
'which range does this hyperlink link to ????

You can find the target by looking at the objHyperlink.Address and
objHyperlink.SubAddress properties.

End If
Next
End If

2. Also, how do I make translate the Word colour constants
into something that I can make any sense of in VB.NET?

The font constants are 32-bit integers representing RGB values. The lest
significant 8 bits are the Red value, the next 8 bits are the Green value
and the next 8 bits are the Blue value. The only expection to this is
wdColorAutomatic, which has a value of -16777216 indicating the default text
or background color (normally black & white respectively, but stored within
Word as a special color)
 
J

Jenny Fletcher

Thanks for your help, but I don't think I made myself
entirely clear with my first question.

So, I have a hyperlink in my contents section, which links
to a heading in the same document, and has a SubAddress
property value of "_Paragraph_2". However, when I inspect
the Paragraph object representing the paragraph that is
linked to the hyperlink, I can't find a property that
indicates this link. So I can't find any way of
discovering the section of text that the hyperlink is
linked to.

I hope that makes sense,

Cheers, Jenny.
 
J

Jonathan West

Jenny Fletcher said:
Thanks for your help, but I don't think I made myself
entirely clear with my first question.

So, I have a hyperlink in my contents section, which links
to a heading in the same document, and has a SubAddress
property value of "_Paragraph_2". However, when I inspect
the Paragraph object representing the paragraph that is
linked to the hyperlink, I can't find a property that
indicates this link. So I can't find any way of
discovering the section of text that the hyperlink is
linked to.

I hope that makes sense,

"_Paragraph_2" is the name of a bookmark within the document. Because the
name startes with an underscore character, it is a "hidden" bookmark, which
is not normally shown in the liat of bookmarks in the Insert Bookmarks or
Edit Goto dialogs.

But if you go to Insert, Bookmark, and then click the "Hidden Bookmarks"
checkbox, all the bookmarks whose names start with an underscore will now
show up in the list, and you can select the one you want and go to it.

Similarly, in code you have to set the ShowHidden property of the Bookmarks
object to True so that the hidden bookmarks become members of the Bookmarks
collection. So if you want to select the text of the "_Paragraph_2"
bookmark, you would need something like this code

With ActiveDocument.Bookmarks
.ShowHidden = True
.Item("_Paragraph_2").Range.Select
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top