Is it possible to assign a specific style to all cross-references in Word 2007?

Solution 1:

Some cross-reference types are automatically formatted with the "intense reference" style, but most are formatted as "normal" text.

To apply the "intense reference" style to the text of the cross reference:

  • select the text
  • choose the "Home" tab in the ribbon
  • using either the up-down buttons or the drop-down button in the "Styles" group of the ribbon, choose the "intense reference" style (or another style if you prefer)

To change the appearance of all text of a given style:

  • choose the "Home" tab in the ribbon
  • using the drop-down button in the "Styles" group of the ribbon, choose "Apply styles..."
  • in the "Apply Styles" dialog box under "Style Name" choose the name of the style you want to change (e.g. "intense reference")
  • Click the "Modify..." button
  • Change the formatting to suit you and click "OK"

To apply a style to all cross references at once:

  • Press Alt+F9 to show field codes
  • Select the "Home" tab in the ribbon
  • Click on "Replace" in the "Editing" group
  • In the "Find what" field, type ^19 REF
    • (That's caret-one-nine-space-R-E-F)
  • Click in the "Replace with" field, but don't type anything
  • Click the "More" button
  • The bottom section of the dialog should be titled "Replace" (with a horizontal rule after it)
  • Click the "Format" button and select "Style..."
  • Choose a style (e.g. "Intense Reference") and click OK
  • It should now show the style you selected under the "Replace with" field
  • Click "Replace All" if you're feeling brave or use "Find Next" and "Replace" to step through and replace or skip each reference field code's style individually
  • Press Alt+F9 to hide field codes

See this page for more information on special codes in Find and Replace.

Here is a macro that will add the switch \* mergeformat to each of the fields. This switch is necessary to keep the formatting from being lost if you do a field update. You can assign the macro to a keystroke and it will step through the fields one at a time for each time you press the keystroke. You can also edit the macro to loop over the whole document to automate the process.

Sub mf()
'
' mf Macro
' Find cross references and add \* mergeformat
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "^19 REF"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:="\* mergeformat "
    Selection.Find.Execute
End Sub

Solution 2:

  • Press Alt+F9 to show field codes
  • Use the following macro to add CHARFORMAT to all cross references. This macro adds the string to the field only if it's not already there.

    Sub SetCHARFORMAT()
    '
    ' Set CHARFORMAT switch to all {REF} fields. Replace MERGEFORMAT.
    '
    '
        Dim oField As Field
        Dim oRng As Range
        For Each oField In ActiveDocument.Fields
        'For Each oField In Selection.Fields
            If InStr(1, oField.Code, "REF ") = 2 Then
                If InStr(1, oField.Code, "MERGEFORMAT") <> 0 Then
                    oField.Code.Text = Replace(oField.Code.Text, "MERGEFORMAT", "CHARFORMAT")
                End If
                If InStr(1, oField.Code, "CHARFORMAT") = 0 Then
                    oField.Code.Text = oField.Code.Text + "\* CHARFORMAT "
                End If
            End If
        Next oField
    
    
    End Sub
    
  • Use this macro to format all cross references with the "Subtle Reference" style (make sure you have such a style, and that field codes are shown):

    Sub SetCrossRefStyle()
    '
    ' Macro to set styole of all cross references to "Subtle Reference"
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Selection.Find.Replacement.Style = ActiveDocument.Styles( _
            "Subtle Reference")
        With Selection.Find
            .Text = "^19 REF"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    
  • Press Alt+F9 to hide field codes

Solution 3:

editing the macro uploaded by the cyborg, we can easily automate showing and hiding the field codes. so that every time we wish to update we do not have to use toggle field codes. I used following code to add field code toggle.

ActiveDocument.ActiveWindow.View.ShowFieldCodes = False

The complete macro is as follows:

Sub SetCrossRefStyle()
'
' Macro to set styole of all cross references to "Subtle Reference"
'
'
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles( _
    "Subtle Reference")
With Selection.Find
    .Text = "^19 REF"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
End Sub

This is the first time I am using macros to speed up my work in word. thanks cyborg for such helpful macro.