PDA

View Full Version : Finding "lost" hyperlinks



YossiD
02-05-2013, 02:20 AM
I work on many documents that have numbered headings and lots of hyperlinks ("See para 3.2," etc.). Sometimes the links get messed up and I end up with "See para 0." Clicking on the link takes me to an unnumbered paragraph, so apparently the target has somehow gotten "lost" and relocated itself to an unnumbered paragraph.

I found some VBA code elsewhere that will find broken links where the target is gone, but it doesn't find links with "lost" targets.

Can anyone recommend some VBA code that will find hyperlinks that refer to a paragraph number 0 (or possibly any paragraph numbers that contain a 0 like 3.0.2)?

TIA

macropod
02-05-2013, 03:46 AM
Hi YossiD,

Hyperlinks don't ordinarily change their display text when updated, so are you sure that's what they are?

YossiD
02-05-2013, 08:15 AM
Hello Paul,

These are cross-references to paragraphs internal to the document: Insert>Reference>Cross-reference>Heading>Heading number), with the Insert as hyperlink option checked (Word 2003). The text of the links updates whenever I update fields in the document.

macropod
02-05-2013, 03:55 PM
In that case, you could use a macro like the following to find & select the errant cross-reference.
Sub Demo()
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
With Fld
If .Type = wdFieldRef Then
If InStr(.Result, ".0.") > 0 Or .Result Like "0.*" Or .Result Like "*.0" Or .Result = "0" Then
.Select
Exit For
End If
End If
End With
Next
End Sub
Simply keep running the macro and fixing the cross-references it selects until none get selected.