WD: How to Use the STYLEREF Field in Microsoft Word

ID: Q141994

The information in this article applies to:

SUMMARY

This article describes how to use the STYLEREF field. The STYLEREF field can be used to create a dictionary-style entries at the top of each page or to place the chapter title in the heading. This field is useful when you want text in the header to match what's typed on the page.

The STYLEREF field is a specialized reference field designed to let you add information to a document, especially in the header or footer, automatically.

The STYLEREF field consists of the field, the name of the style assigned to the text to be returned as the result of the field, and field switches.

   {STYLEREF "StyleName"}
   {STYLEREF "StyleName" <switches>}

   NOTE: The name of the style must be enclosed in quotation marks.

Word will search the page from top to bottom (by default) for the nearest paragraph formatted with the style specified in the STYLEREF field. Word will return that text in the location of the field as the result.

STYLEREF Field Switches

\l - Inserts the last text formatted with the style on the current page

     instead of the first text formatted with this style. Word searches
     the page from bottom to top.

     The \l switch is available only in headers and footers.

\n - Inserts any paragraph numbering from the referenced paragraph. For
     example, caption numbering is included if caption numbering has been
     applied to the paragraph.

The STYLEREF field is most often used in headers and footers. The examples in the "Examples" section of this article illustrate the possible uses of the STYLEREF field.

How to Insert a STYLEREF Field

Method 1: To Create a Field Using the Menus:

1. Position the insertion point in the document where you want to insert

   the text to be entered.

2. On the Insert menu, click Field.

3. In the Categories list box, select "Links and References."

4. In the Field Names list, select "StyleRef."

5. The STYLEREF field will be displayed in the Field Codes text box below

   the Categories list box. Click in the text box to the right of the word
   STYLEREF and type the style name of the text you want to be displayed as
   the field result. For example, type:

      STYLEREF "Heading 1"

   NOTE: You must enclose the text in quotation marks.

6. If a field switch is desired, select the Options button in the Insert
   Field dialog box. Select the field switch, and click the Add To Field
   button. Click OK.

7. In the Insert Field box, click OK.

You will then be returned to the document.

To view the field code you just inserted, press {ALT}+F9.

Method 2: To Create a Field Using Keystrokes:

1. Position the insertion point in the document where you want to insert

   the text.

2. Press {CTRL}+F9.

   Field code brackets, {}, will appear in the document.

3. Type the following inside the filed code brackets, where <stylename> is
   the name of the style applied to the text that you  to be displayed:

      STYLEREF "<stylename>"

   NOTE: You must enclose the text in quotation marks.

EXAMPLES

Case 1--Using STYLEREF Fields in a Dictionary/Glossary

Use the STYLEREF field when creating a glossary to show the first and last glossary words on each page--the same format you'll find in a dictionary.

   If the field codes resemble the following

      {STYLEREF "Heading 2"}--{STYLEREF "Heading 2" \l}

   the result of the field codes will be:

      Apple - Baseball (where Apple and Baseball have been formatted with
                        Heading 2 style)

Case 2--Chapter Title to Appear in the Header

Use this format to insert the current chapter name as part of the header or footer.

   If the field code resembles the following

      {STYLEREF "Heading 1"}

   the result of the field in the header will be:

      File Management    (where File Management was the title of the
                          chapter formatted with Heading 1 style)

MORE INFORMATION

Effective Use of the STYLEREF field

To use the STYLEREF field effectively, you need to understand how Word determines which paragraph is the nearest one. That determination depends on where the STYLEREF field is and on whether the /l (the letter L) switch is being used.

   If STYLEREF
   is here            Word will search here
   -----------------------------------------------------------------------

   Document Text      From the field code to the beginning of the document
                      and then from the field code to the end of the
                      document.

   Footnotes,         From the reference mark in the document to the
   Annotations,       beginning of the document, and then from the
   and Endnotes       reference mark to the end of the document.

   Headers and        From the beginning of the current page to the end of
   Footers            that page, and then from the end of the previous page
                      to the beginning of the document, and then from the
                      beginning of the following page to the end of the
                      document.

                      If the \l switch is used, Word searches from the
                      end of the current page to the beginning of the
                      document, and then from the beginning of the
                      following page to the end of the document.

REFERENCES

For more information about the STYLEREF field, click the Index tab in Microsoft Word 7.0 Help, type the following text

   STYLEREF

and then double-click the selected text to go to the "Field codes: StyleRef field" topic.

In Microsoft Word 6.x, click the Search menu in Help and type

   STYLEREF

and then double-click the selected text to go to the "Field codes: StyleRef field" topic.

Additional query words:

Keywords          : wordnt kbfield winword ntword macword word6 word7 word95 
Version           : WINDOWS:6.0,6.0a,6.0c,7.0,7.0a;MACINTOSH:6.0,6.0.1,6.0.1a
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: January 22, 1999