Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Controlling the Format of Cross-References.

Controlling the Format of Cross-References

by Allen Wyatt
(last updated February 1, 2014)

6

Stephen asked if it is possible to control the format of cross-references inserted by Word. When he inserts a label and number such as Table 1 or Figure 12, he wants the label lowercase (table, figure) and a non-breaking space between the label and the number.

There is no way to control this type of cross-reference formatting in Word. Obviously you can change the cross-references manually after placing them, but whenever you update fields the original Word-chosen format will be used for them. There are a couple of macro-based solutions you can try. The first solution will change the actual field codes used for the field:

Sub FieldRefChanges1()
    On Error Resume Next
    Dim oStoryRng As Range
    Dim oFld As Field

    For Each oStoryRng In ActiveDocument.StoryRanges
        For Each oFld In oStoryRng.Fields
            If oFld.Type = wdFieldRef And oFld.Result.Words.Count <= 2 Then
                'add format switch with lowercase option to field codes
                oFld.Code.Text = oFld.Code.Text & "\* lower "
                'updates the field results to display the new format
                oFld.Update
            End If
        Next oFld
    Next oStoryRng
End Sub

The macro includes a couple of nested For loops. The first one steps through each story in the document, and the second goes through each field in each story. An If statement is then used to make sure that the field is a REF field (the kind used for cross-references) and that the result of the field is two or fewer words (as in Table 1 or Figure 12).

If these criteria are met, then the macro makes a change to the actual field code, adding the switch that results in the field being displayed in lowercase.

There are a couple of drawbacks to this macro. First, if you run it multiple times, the \* lower switch is added to the REF fields multiple times. Second, the macro doesn't change the space in the field results to a non-breaking space.

To overcome both problems, just modify the macro so that it automates the manual process you would go through to change the macro results.

Sub FieldRefChanges2()
    On Error Resume Next
    Dim oStoryRng As Range
    Dim oFld As Field
    Dim sTemp As String
    Dim J As String

    For Each oStoryRng In ActiveDocument.StoryRanges
        For Each oFld In oStoryRng.Fields
            If oFld.Type = wdFieldRef And oFld.Result.Words.Count <= 2 Then
                sTemp = oFld.Result.Text
                sTemp = LCase(sTemp)
                J = InStr(sTemp, " ")
                sTemp = Left(sTemp, J - 1) & Chr(160) & _
                  Mid(sTemp, J + 1, Len(sTemp) - J)
                oFld.Result.Text = sTemp
            End If
        Next oFld
    Next oStoryRng
End Sub

This macro is essentially the same as the previous one, except that it works strictly with the result text for the field. The text is assigned to the sTemp variable, which is then converted to lowercase. The position of the space is determined, and it is replaced with a non-breaking space. The result is then stuffed back into the result text for the field.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8479) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Controlling the Format of Cross-References.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting a File

Need to combine several files into a single document? You can do it by inserting one file into another, as outlined in this ...

Discover More

Inserting and Copying Rows

Want an easy way to insert a new row in a worksheet and copy everything from the row above? (You end up with two identical ...

Discover More

Changing Existing Captions

Word allows you to automatically create captions for various elements of your document, such as figures and tables. These ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Setting Defaults in the Cross-reference Dialog Box

Some types of documents rely on cross-references quite a bit. Setting up the Cross-reference dialog box the first time in ...

Discover More

Referencing a Page Number In Another Document

Page references are a common element of many documents. If you need to have a page reference to a page in a different ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 0 + 6?

2014-12-10 17:58:41

Daniel

Jennifer, thanks so much for your response. That's exactly it; solves my x-ref issue perfectly. I knew it would be something easy, but my feeble brain was so fixated on editing the Field Code/Switchcodes that I never in a million years would have thought about hard typing "Article" in the numbering definition setup and then overlaying the All Caps font attribute. But that's exactly what's needed to get the x-reference to appear correctly in the narrative text of the doc. But try and find that answer anywhere else on the internet!?! I couldn't.

And part of the reason the doc Heading styles aren't set up this way at the place where I work is because we use Payne Numbering Assistant for our numbering setups, and she has the word ARTICLE hard typed in ALL CAPS in all her Article headings. So those levels need to be modified by the user per your method if x-ref'ing is needed in a particular doc.

Thanks again for your response. Much appreciated.


2014-12-10 08:31:20

Jennifer Thomas

Daniel, check the way the word Article is typed/formatted in the number format field of the scheme.

Best practice is to type in Title Case, but use the Font effect of All Caps to make it display as ARTICLE (this allows for upper case display in a numbered paragaraph but title case display in a cross reference, which sounds like what you are describing).

If you want ARTICLE (all caps) in the Cross Reference, just type it in all caps in the number format field, and the cross reference will display it that way.


2014-12-10 00:28:05

Art Hendrickson

Daniel,

Please post the complete field code/codes you're using (e.g., { Ref heading * roman * MERGEFORMAT }). ITMT, you might:
1. review https://support.office.com/en-ie/article/Insert-and-format-field-codes-in-Word-2010-7e9ea3b4-83ec-4203-9e66-4efc027f2cf3
2. experiment with field codes embedded within another field code (e.g., { ref w t { Styleref
} }


2014-12-09 00:42:17

Daniel

I've never known how to cross-reference to a heading in all caps with a Roman Numeral such as "ARTICLE III" but to have it appear "Article III" in the narrative via the cross-reference field. I can get edit the Field Code for Initial Cap. but then it changes it to "Article Iii"

How do you edit the cross-reference field code to change the case of the word ARTICLE to Initial Cap while not changing the Roman Numeral at all?


2014-02-03 08:52:54

Jennifer Thomas

Here is a macro to put non-breaking spaces in common phrases for corporate documents; as Art mentioned, this solves the issue of the breaking cross reference too.

You can add other terms to the array as needed (just use the existing syntax as a sample); remember to increase each instance of '24' in the macro below to match the total number of terms used.

Sub HardSpacesAfterTerms()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Dim i As Integer
Dim textString As String
Dim aWd(1 To 24) As String 'Increase upper bound number to equal the total number of items added below


'Array of Month names
aWd(1) = "January "
aWd(2) = "February "
aWd(3) = "March "
aWd(4) = "April "
aWd(5) = "May "
aWd(6) = "June "
aWd(7) = "July "
aWd(8) = "August "
aWd(9) = "September "
aWd(10) = "October "
aWd(11) = "November "
aWd(12) = "December "

'Array of Other terms
aWd(13) = "Exhibit "
aWd(14) = "Section "
aWd(15) = "Article "
aWd(16) = "Paragraph "
aWd(17) = "Schedule "
aWd(18) = "Exhibits "
aWd(19) = "Sections "
aWd(20) = "Articles "
aWd(21) = "Paragraphs "
aWd(22) = "Schedules "
aWd(23) = "clause "
aWd(24) = "clauses "

For i = 1 To 24 'Increase to match number of terms used
textString = aWd(i) & Chr(160)
rDcm.Find.Execute FindText:=textString
If rDcm.Find.Found = True Then
GoTo SkipToNext
Else
With rDcm.Find
.Text = aWd(i)
.Replacement.Text = aWd(i) & Chr(160)
.Forward = True
.Wrap = wdFindStop
.MatchCase = True
.Execute Replace:=wdReplaceAll
End With
With rDcm.Find
.Text = " " & Chr(160)
.Forward = True
.Wrap = continue
.MatchWildcards = True
.Replacement.Text = Chr(160)
.Execute Replace:=wdReplaceAll
End With
End If
SkipToNext:
Next i

Set rDcm = Nothing

End Sub


2014-02-02 12:13:36

Art Hendrickson

Put a non-breaking space between the label and the number in the original caption and the non-breaking space will appear in any reference to that caption.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.