h1

Word: Use StyleRef field to populate header/footer

January 30, 2009

Many corporate documents require you to have a table near the beginning of the document with details such as the author, the date created, a revision number etc. You may also be required to insert some of these details into the header and/or footer of the Word document.

While you can set up all sorts of macros, cross-references, document property fields etc. to do this, here’s a really quick solution using styles and the StyleRef field. This solution works in both Word 2003 and Word 2007. Before attempting this, you should know how to create a new style in your version of Word.

  1. Create new styles for the text elements you want to capture. Give these styles names that are unique and are unlikely to be used anywhere else in the document (this is critical).  For example, DocAuthor, DocDate, DocTitle, DocRevNum. Don’t worry about formatting — the header/footer styles will control that.

    Create new styles

    Create new styles

  2. Fill in the details in the document information table (create a table if it doesn’t already exist).
  3. Apply the relevant styles to each cell of the document information table — e.g. apply the DocTitle style to the cell containing the title.  DO NOT apply these styles anywhere else in the document — only one paragraph/cell in the entire document should have this style applied to it otherwise this solution won’t work.

    Apply the new styles to the relevant cells

    Apply the new styles to the relevant cells

  4. Open the header or footer (Word 2003: View > Header and Footer; Word 2007: Insert > Header > Blank then remove the control).
  5. Insert a StyleRef field for each of the elements you want to populate.  To insert a field: Word 2003: Insert > Field; Word 2007: Insert > Quick Parts > Field. Select StyleRef from the list of field names on the left (1), then select the style (e.g. DocAuthor) from the list of style names on the right (2), and click OK (3).

    StyleRef field

    StyleRef field

  6. Repeat step 5 for the other StyleRef fields you want to add. Add words, spaces, punctuation etc. between the fields, as required.

    Header created from the styles

    Header created from the styles

  7. Voila! Instant header/footer populated with the document details. And even better — as soon as you update any of the data in the cells, the header/footer automatically updates too.

    Instant update

    Instant update

If you want to see what’s going on behind the scenes, you can always toggle the field codes in the header/footer to see how it works:

Raw field codes

Raw field codes

(Thanks to Ken E on the STC Lone Writers discussion list who shared this technique with us.)

You can buy me a coffee if this tip helped you Has this tip helped you? saved you time? saved your skin? You can thank me by clicking on the cup and buying me a coffee. (An E-Junkie shopping cart page will open where you can pay for my coffee via PayPal.)

9 comments

  1. Thanks! I haven’t had to use many of the “advanced” features yet, so hadn’t looked into this, but it will be great to know when I need it.


  2. This is the best solution among several I’ve tried to automatically populate headers/footers. It is the most elegant and has the added bonus of not having to use code and having to deal with associated security issues. I found out early on that you can’t use bookmarks there like you can in the body of the document, and what would be really simple in Excel (=cell) is much more complicated in Word (as expected).

    Thanks!


  3. thank you very much. you solved my problem simply


  4. Note:
    Additional info: make sure you don’t use Adobe version 8 or 9 to convert your documents to pdf files. These versions add stray characters to your final pdf files in the headers before the styleref field. This problem has been pointed out to Adobe but so far they seem unable to do something about it… so if you are using an older pdf maker version HANG ON TO IT!


  5. This works very well. But my problem is that I am using a Date Picker Content control in Word 2007 on the Title page to standardize the special date formatting, and I need to have that same date in my header. I used the StyleRef trick and it’s fabulous, but the date is now surrounded by . How can these be removed? I have tried using a bookmark and cross-reference, which works well in the body of the text, but not in the header since it does not allow me to have have one font style on the title page, and a different font style in the header.


  6. Very nice Rhonda. Thanks for taking the time to put together this nice explanation.


  7. [...] if I reference this TOC Heading style in a field using the StyleRef field code, I get a left arrow character inserted as part of the field in front of the Table of Contents [...]


  8. Please help!

    I am editing a manual with about 600 pages and 23 Sections, labeled A through V. I often do changes to several of the pages, which changes the revision number on the those pages. Section A contains a section called “List of Effective Pages.” The List of Effective Pages contains a three column multi row table containing three pieces of data from each page in the document: the page number, the revision number, and the effective date. Is there a way, after I change some of the pages, that each of these pieces of data, which are contained in the header and/or footer, be automatically updated like in a Table of Contents and imported into the table in Section A?


  9. Hi Dan

    I think you’re asking a little too much from Word in this instance! If it was a database, then there’s very likely a way you can do this.

    It’s possible that a macro might do it, but I’d have no idea where to start. I suggest you ask your question over on the Word forums on the Microsoft Answers site: http://answers.microsoft.com/en-us/office/forum/word

    –Rhonda



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 104 other followers