Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2023 by Barry MacDonnell. All Rights Reserved.

Page updated May 18, 2016

Find broken cross references.wcm - A macro that finds any broken cross reference link so that you can fix or remove the cross reference

Download FindBrokenXRef.zip
(v1.04; 08/17/2014; 17,024 bytes)

Written in WordPerfect X7 but should work in other versions.

WordPerfect 11 users: See important information about using macros in the first release of WP11 ( at the top of this page.

Downloading, Documentation, Modifications, and Support

Disclaimer, Distribution, and Privacy Policies

Some related pages containing information and tips on cross references

Convert cross reference numbers (macro)

Footnotes and endnotes

Using WordPerfect counters

Graphic tips

Why some hyperlinks (hypertext links) can fail

Starting, stopping, and toggling the automatic numbering (and bullet) feature


The following menu choices refer to the <WordPerfect> menu (right-click on the top menu bar for a choice of menu).

If you use a <Microsoft Word> menu, the choices might be absent from your menu (but not from the program), or they might be found under another menu selection. See here for more.


Whenever cross references are generated (with Tools> Reference> Generate or Alt+Shift+F5) a number appears at the reference (or "pointer") location in the text, depending on the Reference Type -- for example, a page number or a footnote number. Generally you will add leading text to help the reader identify the reference, such as "See page _", or "See footnote _".

From WPX7 Help ("Working with cross references"):

"... Cross-references are comprised of a target and a reference. The target is the item or text to which you are referring: the page number, figure, or footnote. The reference is the document text that you use to refer to the page number, figure, or footnote; it often displays as "See page 23."

[N.B.: The user must type the "See page " characters into the document, and then insert the [Ref] code using the Reference Tools dialog. The code will display the actual number when all references have been Generated (see Instructions below).]

... You can cross-reference page numbers and chapter numbers, footnote and endnote numbers, caption numbers, graphics boxes, counter numbers, and paragraph and outline numbers. In order to create a cross-reference, you must mark first the target and then the reference. Before you generate a document, the cross-references are represented by question marks. When you generate the document, the cross-reference numbers display. ..." [Bold/Italics mine.]

Why use this macro?

When a cross-referenced document is generated (or re-generated) a question mark ("?") indicator appears in place of a number to indicate a broken link (for example: "See page ?").

    Typically, such broken cross references are due to deleting one of the codes responsible for creating the link between the reference and the material being referenced. (For example, deleting a block of text that contains the target code also deletes the code.)

    Even though the "?" indicator is visible, it can go unnoticed -- hence the reason for this macro, which helps you quickly located a broken cross reference so you can fix it or remove it.

    [The "?" indicator is not a text character, so it cannot be searched with Edit> Find and Replace or (normally) by a macro. This macro, however, uses a simple trick to determine if the indicator refers to a broken link.]


Download the macro to your computer (if you need help, see the "Downloading..." link in the box in the left column).

- Then -

[1]  Make a backup of the document.
(Always a good idea!)

This macro makes temporary changes to the current document during processing (it then immediately reverses them -- but you can't be too careful, so work on a copy of the document).

[2]  Generate the document containing cross references with Tools> Reference> Generate before playing this macro to ensure that any broken cross references display the "?" indicator.

[3] Play the macro to search for a broken link. (Screen shot of menu.)

    When you play this macro it looks for cross-reference links that were broken between the [Ref...] code and the [Target] code.

    Since a broken link cannot be determined by simply searching for these codes or by using a macro command to extract the internal value of them, here's how this macro does it:

    Starting at the top of the document the macro searches for instances of each of the possible nine types of [Ref...] code -- including searching inside "substructures" such as headers, footers, footnotes, endnotes, etc.

    When one is found, the [Ref] code at that location is selected, deleted, and then immediately pasted back in place as Unformatted text. This method temporarily turns the displayed value of the [Ref] code into an ordinary text character. The text character is then quickly tested to see if it is a question mark (before restoring the character back to the original code).

[4]  If the item found is a question mark -- that is, it's an indicator of a broken link -- the macro displays a brief message and immediately quits at that location to allow you to manually repair the link between the reference and its target.

•  You can make the repair by deleting the [Ref] code in Reveal Codes and then create a new cross reference at that location to the desired target material with Tools> Reference> Cross Reference.

•  By default, the macro leaves Reveal Codes open (in case it was previously closed) so that you can examine the reference code (see the notes and tips section below) to help diagnose the location of the missing [Target] code area. You can turn it off again later with View> Reveal Codes.

[5]  Once you repair the broken cross reference, repeat steps #2 and #3 as needed.

If no broken links are found, the macro will exit with a message to that effect.

Important notes and tips

  As noted above (and because of limitations in the macro language) the macro does not automatically repair the broken link. You have to do it manually by using Tools> Reference> Cross-Reference and re-establishing a new cross reference to the new marked Target.

In any case, you probably will want to verify the Target area's adjacent text when repairing the link to ensure it is as you require. Typically a broken cross reference is due to deliberately or accidentally deleting the cross reference's [Target] code in the document's text, perhaps when that area's material was last edited.

  When the macro finds a broken link, in the Reveal Codes window (View> Reveal Codes) you should see the related [Ref] code at the cursor location. If you click inside the Reveal Codes window and place the insertion cursor to the immediate left side of the code, you should see information about that code displayed directly on the code itself. [See here for more tips on Reveal Codes.]

This can help you locate the target text area in the document, since (most often) targets are marked by selecting some text at that location before using the Mark Target button. The selected text should then appear directly on the [Ref] code when you Generate the document.

In a similar way, you would repair the broken link by first selecting some text at that (target) location and using the Mark Target button in the Reference Tools dialog. Then you would return to the reference ("pointer") location and use the Mark button to create the [Ref] code there. Then you would Generate the document again to activate that link, and then play the macro again to search for any other broken links.

(New in v1.03:) While the macro plays it displays a message on screen showing a count of each item type and a running total. If you wish to pause the message at the end of each search for the 9 types of cross references, you can use a setting in the redlined User Modification Area at the top of the main macro code. It will pop an OK/Cancel message at the end of each cross reference type search.