I have a Word document that contains cross-references:
See "Start the machine" on page 15.
The text "Start the machine" is a hyperlink object, and '15' is a PageRef field. I want to use a macro to apply a character style to "Start the machine" on page 15.
I created this macro that finds the hyperlink. My idea was to select the link, and extend the selection until it contains the PageRef.
Sub ExtendCrossref()
Dim HL As Hyperlink
For Each HL In ActiveDocument.Hyperlinks
HL.Range.Select
Do Until Selection.Fields.Count > 1
Selection.Range.MoveEnd wdWord, 1
Debug.Print Selection
Loop
Next
End Sub
I can't get Selection.Range.MoveEnd to work: after the loop, the selection remains "Start the machine" when it should be "Start the machine" on.
I've also tried Selection.Extend, didn't work either.
How can I add words to the selection?