Word: Use StyleRef field to populate header/footerJanuary 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 Word 2003, Word 2007 and Word 2010 at least. Before attempting this, you should know how to create a new style in your version of Word.
- 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.
- Fill in the details in the document information table (create a table if it doesn’t already exist).
- 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.
- Open the header or footer (Word 2003: View > Header and Footer; Word 2007/2010: Insert > Header > Blank then remove the control OR double-click in the header space to open the header).
- Insert a StyleRef field for each of the elements you want to populate. To insert a field: Word 2003: Insert > Field; Word 2007/2010: 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).
- Repeat step 5 for the other StyleRef fields you want to add. Add words, spaces, punctuation etc. between the fields, as required.
- 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.
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:
(Thanks to Ken E on the STC Lone Writers discussion list who shared this technique with us.)