Word: Use StyleRef field to populate header/footer

25 Dec

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.

http://cybertext.wordpress.com/2009/01/30/word-use-styleref-field-to-populate-headerfooter/

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, DocAuthorDocDate,DocTitleDocRevNum. Don’t worry about formatting — the header/footer styles will control that.
    Create new stylesCreate 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 cellsApply the new styles to the relevant cells

  4. Open the header or footer (Word 2003View > Header and Footer;Word 2007Insert > 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 2003Insert > FieldWord 2007Insert > 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 fieldStyleRef 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 stylesHeader 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 updateInstant 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 codesRaw field codes

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