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. Such as when click on table 1 it takes it to table 1. This is extensive review and many times we miss it. Can I get help to create VBA code/run macro to check if all the links are working? is it even possible? Add-in tool? thanks and looking forward to have some solution.
1 Reply
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