R
Rob
Hello;
First my purpose.....to help a friend with an office automation problem
(see other posts I have made) with updating the text that is displayed in
hyperlinks. It may be that using some other field or tag may work
better..opinions and solutions please...
NOTE: Some of the below code is from other posts/contributors in this forum
(Thank You macropod!).
The problem is in legal pleading type pages, there needs to be a table with
a column of crossreferences that list the page and linenumber (that may not
be possible to do automatically I am finding) or section/heading/numbering.
Some type of fields will automatically update on F9 like page number using
the PAGE or PAGEREF field code. Same thing with almost everything except line
number. In order to exploit if a line number solution is possible I am
enumerating the various properties of the fields. At the moment (having never
used the office automation but having C#/Ansi C/ and some VB5-6 experience) I
am struggling to get the included below code to do the following (it seems
pertinent to do, but if I am in error please advise me so):
Cycle through all the fields in the ActiveDocument
<seems to work> If the field is a hyperlink, display the Text to display,
target, address, subaddress, index number.
<does not work> Then using the index number, access the hyperlink object
from the hyperlinks collection using the
index number to get/display the properties.
<note coded yet> If the field is a bookmark,
display the Title of the bookmark,
display the page it is located on,
most importantly (I think) is get the
character range (ie start and end)
so that I might be able to get the
linenumber from one of the properties of the range object
after setting the range object to the
bookmarks start and end position.
<note coded yet> For each hyperlink, change the Text to display to the
following formatage/LineNumber or Page,LineNumber
<seems to work> Count total of HyperLinks in document
Please advise where I have improperly coded or assumed the schema. I am
working in Office 2002 SP3.
References are:
Visual Basic for Applications
Microsoft Word 10.0 Object Library
OLE Automation
Normal
Microsoft Office 10.0 Object Library
Do I have to Dimension a hyperlink object and then if the field.type is
hyperlink, then do hyperlink=field in order to get the Address? Or is the way
I am trying below the better approach?
Sub HLinkTest()
Dim oFld As Field
Dim oCount As Integer
Dim oRange As Word.Range
With ActiveDocument
.Range.AutoFormat
For Each oRange In .StoryRanges
Do
For Each oFld In oRange.Fields
If oFld.Type = wdFieldHyperlink Then
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Result= " & oFld.Result, vbOKOnly, "oFld.Result"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Kind= " & oFld.Kind, vbOKOnly, "oFld.Kind"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Code= " & oFld.Code, vbOKOnly, "oFld.Code"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.ShowCodes= " & oFld.ShowCodes, vbOKOnly, "oFld.ShowCodes"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Index= " & oFld.Index, vbOKOnly, "oFld.Index"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).Target, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).Target"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).Address, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).Address"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).SubAddress, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).SubAddress"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay"
oCount = oCount + 1
End If
If oFld.Type = wdBookmark Then
MsgBox "BM oFld.Result= " & oFld.Result, vbOKOnly,
"oFld.Result"
End If
Next oFld
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next oRange
MsgBox "Total Detected HyperLinks=" & oCount
End With
End Sub
Thanks...I feel the programming pain, where is the gain?
Rob
First my purpose.....to help a friend with an office automation problem
(see other posts I have made) with updating the text that is displayed in
hyperlinks. It may be that using some other field or tag may work
better..opinions and solutions please...
NOTE: Some of the below code is from other posts/contributors in this forum
(Thank You macropod!).
The problem is in legal pleading type pages, there needs to be a table with
a column of crossreferences that list the page and linenumber (that may not
be possible to do automatically I am finding) or section/heading/numbering.
Some type of fields will automatically update on F9 like page number using
the PAGE or PAGEREF field code. Same thing with almost everything except line
number. In order to exploit if a line number solution is possible I am
enumerating the various properties of the fields. At the moment (having never
used the office automation but having C#/Ansi C/ and some VB5-6 experience) I
am struggling to get the included below code to do the following (it seems
pertinent to do, but if I am in error please advise me so):
Cycle through all the fields in the ActiveDocument
<seems to work> If the field is a hyperlink, display the Text to display,
target, address, subaddress, index number.
<does not work> Then using the index number, access the hyperlink object
from the hyperlinks collection using the
index number to get/display the properties.
<note coded yet> If the field is a bookmark,
display the Title of the bookmark,
display the page it is located on,
most importantly (I think) is get the
character range (ie start and end)
so that I might be able to get the
linenumber from one of the properties of the range object
after setting the range object to the
bookmarks start and end position.
<note coded yet> For each hyperlink, change the Text to display to the
following formatage/LineNumber or Page,LineNumber
<seems to work> Count total of HyperLinks in document
Please advise where I have improperly coded or assumed the schema. I am
working in Office 2002 SP3.
References are:
Visual Basic for Applications
Microsoft Word 10.0 Object Library
OLE Automation
Normal
Microsoft Office 10.0 Object Library
Do I have to Dimension a hyperlink object and then if the field.type is
hyperlink, then do hyperlink=field in order to get the Address? Or is the way
I am trying below the better approach?
Sub HLinkTest()
Dim oFld As Field
Dim oCount As Integer
Dim oRange As Word.Range
With ActiveDocument
.Range.AutoFormat
For Each oRange In .StoryRanges
Do
For Each oFld In oRange.Fields
If oFld.Type = wdFieldHyperlink Then
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Result= " & oFld.Result, vbOKOnly, "oFld.Result"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Kind= " & oFld.Kind, vbOKOnly, "oFld.Kind"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Code= " & oFld.Code, vbOKOnly, "oFld.Code"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.ShowCodes= " & oFld.ShowCodes, vbOKOnly, "oFld.ShowCodes"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
"oFld.Index= " & oFld.Index, vbOKOnly, "oFld.Index"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).Target, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).Target"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).Address, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).Address"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).SubAddress, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).SubAddress"
If Left(oFld.Result, 7) = "mailto:" Then MsgBox
ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay, vbOKOnly,
"ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay"
oCount = oCount + 1
End If
If oFld.Type = wdBookmark Then
MsgBox "BM oFld.Result= " & oFld.Result, vbOKOnly,
"oFld.Result"
End If
Next oFld
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next oRange
MsgBox "Total Detected HyperLinks=" & oCount
End With
End Sub
Thanks...I feel the programming pain, where is the gain?
Rob