Why can I still see my Hidden Cross Reference?

Follow

If a cross reference (or any other field), is included in conditional content then you need to ensure the field code includes the MERGEFORMAT switch. Without the MERGEFORMAT switch the field will not be hidden when the conditional content is hidden.

Here is an example of a conditionalized field that is missing the MERGEFORMAT switch:

Field code without MERGEFORMAT switch

This field will still be visible when this conditional content is hidden because the MERGEFORMAT switch has been omitted.

Here is an example of the same conditionalized field with the MERGEFORMAT switch:

Field code with MERGEFORMAT switch

This field will be hidden when this conditional content is hidden because the MERGEFORMAT switch has been included.

Typically, Microsoft® Word automatically includes the MERGEFORMAT switch when fields are created. However, sometimes it omits the MERGEFORMAT when a REF field is created.

You can ensure the MERGEFORMAT switch is included in a field by checking the Preserve formatting during updates option in the Fields dialog box or by using ALT + F9 to toggle the display of field codes and manually adding the MERGEFORMAT switch to the appropriate fields.

How can I find cross reference fields that are missing the MERGEFORMAT switch

You can use the VBA macro below to scan your document for cross reference fields that are missing the MERGEFORMAT switch.

If this macro finds any cross reference fields missing this switch, then a new document will be opened that contains the page and line number of the offending cross reference fields.

Sub ReferenceFieldsMissingMergeFormat()
    
    Dim field As Field
    Dim code As String
    Dim result As String
    
    ' /////////////////////////////////////////
    ' // Get REF fields missing MERGEFORMAT. //
    ' /////////////////////////////////////////
    
    For Each field In ActiveDocument.Fields
    
        If field.Type = wdFieldRef Then
        
            code = LCase(field.Code.Text)
    
            If Not InStr(code, "mergeformat") Then            
                result = result & "Page " & field.Code.Information(wdActiveEndPageNumber) & ", "
                result = result & "Line " & field.Code.Information(wdFirstCharacterLineNumber) & ": "
                result = result & field.Code.Text & vbVerticalTab
            End If
        
        End If
        
    Next field
    
    If result = "" Then
        MsgBox "There are no cross reference fields missing the MERGEFORMAT switch in this document."
        Exit Sub
    End If
    
    ' ///////////////////////////////////////////
    ' // Open new document and output results. //
    ' ///////////////////////////////////////////    
    
    Dim document As Document
    Set document = Documents.Add
    
    document.Content.Text = "Cross reference fields missing the MERGEFORMAT switch" & vbCr & result

End Sub

To Create this Macro in Microsoft Word

  1. Select the Developer tab.
  2. Select Macros.
  3. Type ReferenceFieldsMissingMergeFormat in the Macro name field.
  4. Click Create.
  5. Copy the contents of the macro code above.
  6. Paste it in between the Sub and End Sub lines.
  7. Click Save and Close.

To Execute this Macro Reopen Microsoft Word

  1. Select the Developer tab.
  2. Select Macros.
  3. Select the macro named ReferenceFieldsMissingMergeFormat.
  4. Click Run.
Article modified

Comments

  • Avatar
    Keith Mahoney

    Great Macro - Thank You!!

    It did "reveal" where the X-Ref did not contain \* MERGEFORMAT. However, having to manually change these is painful - when you have 20+; and:

    1. The page number and line number do not match.
    2. Would be nice if the Marco contained a "Update and Replace" option - would save a ton of manual time - Any possiblity?
  • Avatar
    Keith Mahoney

    Great Macro - Thank You!!

    It did "reveal" where the X-Ref did not contain \* MERGEFORMAT. However, having to manually change these is painful - when you have 20+; and:

    1. The page number and line number do not match.
    2. Would be nice if the Marco contained a "Update and Replace" option - would save a ton of manual time - Any possiblity?
  • Avatar
    Keith Mahoney

    Great Macro - Thank You!!

    It did "reveal" where the X-Ref did not contain \* MERGEFORMAT. However, having to manually change these is painful - when you have 20+; and:

    1. The page number and line number do not match.
    2. Would be nice if the Marco contained a "Update and Replace" option - would save a ton of manual time - Any possiblity?
  • Avatar
    Keith Mahoney

    Great Macro - Thank You!!

    It did "reveal" where the X-Ref did not contain \* MERGEFORMAT. However, having to manually change these is painful - when you have 20+; and:

    1. The page number and line number do not match.
    2. Would be nice if the Marco contained a "Update and Replace" option - would save a ton of manual time - Any possiblity?
Please sign in to leave a comment.
Powered by Zendesk