Forum Discussion
maihar
Oct 07, 2025Copper Contributor
VBA Code/possible
I have a document where I have tables, figures, and cross-reference tables, figures links to text. Currently, I and my team checks manually if all the links working and going to correct destinations....
Kidd_Ip
Oct 12, 2025MVP
Take this:
Sub CheckCrossReferences()
Dim fld As Field
Dim refType As String
Dim refTarget As String
Dim msg As String
Dim countBroken As Integer
Dim countTotal As Integer
countBroken = 0
countTotal = 0
msg = ""
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldRef Then
countTotal = countTotal + 1
On Error Resume Next
refTarget = fld.Result.Text
If fld.Result = "" Or InStr(1, fld.Code.Text, "\h") = 0 Then
msg = msg & "Broken or non-hyperlinked reference: " & fld.Code.Text & vbCrLf
countBroken = countBroken + 1
End If
On Error GoTo 0
End If
Next fld
msg = msg & vbCrLf & "Total cross-references: " & countTotal & vbCrLf
msg = msg & "Broken or missing hyperlinks: " & countBroken
MsgBox msg, vbInformation, "Cross-Reference Check"
End Sub