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 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.

  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/2010: Insert > Header > Blank then remove the control OR double-click in the header space to open the header).
  5. 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).

    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.)


  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).


  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


  10. hi! thanks very much, your article helped me a lot, actually I really had problems with how do deal with these footer/header, finally I found the answer from here. great job!

  11. Hi,
    It is really neat and well illustrated solution on this topic.
    Thank you very much. Keep up the good work.


  12. I have the issue with Track Changes used in the referenced style not showing in the Header with the StyleRef field. The text appears but, in this case, is not strikethrough. So my setup is the “Date” style at the top of the letter. With Track Changes on the date is changed on page one and shows the new date and the strikethrough on the old date. In the Header on page two it shows both dates but no strikethrough. Any ideas on how to get this formatting to show in the field?

  13. Hi Alan

    I just tried it and I get the same thing as you, except I get both dates in ALL places (none except the original source date field have track changes marked for them). I checked the field code, and there’s just one for the ‘combined’ date so it’s not like it’s showing two fields.

    I don’t have a solution for you, except to suggest you accept the change for this field if you are able to do so. However, corporate requirements may mean you have to leave it on until the changes have been ratified, in which case I’d let the next set of reviewers know about this anomaly and tell them to ignore it.


  14. That’s what I had assumed I’d have to do. The client is a law firm so it I’ll just work with the apps person to find a best practice. Thanks

  15. That, in theory does exactly what I want to do. Thanks very much. I only need one field “Version” which I have created as a style. I inserted the field into the centre of the footer (with Document title on the left and Page X of X on the right). The version shows up nicely on page one, but does not display on any other pages. I’m using word for Mac 2011 version 14. Any ideas?

  16. Hi Paul

    I don’t know how different Word for Mac is from Word for Windows, but in Word for Windows there’s a setting in the header/footer tab for ‘Different First Page’. It’s possible that’s selected.


  17. I have used STYLEREF many times with no problem, but right now I got an error, stating that there is no text in the document with the requested style (or whatever the English equivalent may be).
    What I tried to do was actually the opposite: I had the text that formed the name of the project, formatted with a style called “Project”, but I had that text piece in the header, and tried to populate the footer with it. It didn’t work. Is there a problem referring to styles that are contained in a Header/Footer?



  18. Hi Bengt

    I just tested this, and I get the error too. The only thing I can assume is that you can’t use a StyleRef field in a header for a unique style that’s in the footer (and vice versa).

    Of course, if the text is already in the header, I’d query why you want to repeat it in the footer anyway (or vice versa).


  19. Hi Rhonda,
    Thanks for your answer. Yes, I guess it is a fair question to ask, why you would repeat in the footer if it is in the header. However, this is what my job situation required me to do, and since this doesn’t seem to be possible to do, I guess my only option is to put the text somewhere in the document text. By doing so, I can obvously refer to if both in the header and the footer. Strange limitation though. As I said, I have been using Styleref a lot, but clearly, not in this fashion.


  20. Hi Rhonda,
    I’m trying to add two stylerefs to the header with a tab in between and I’m getting just the first field. I’ve tried adding just a space between, and the word “and” without any luck. Any ideas?

  21. Hi Karen

    The actual styles should only ever be used once in the document — that means a single use of one of these special styles in ONE paragraph or ONE cell of a table (see Step 3 above). Assuming that’s the case, then you should be able to insert styleref fields that refer to one or more of those special styles in the same paragraph (see Steps 5 and 6).

    Something might be getting messed up when you insert the tab — have you tried toggling field codes on to make sure you are entering the tab AFTER the field code curly braces? (You can show all field codes temporarily by setting this in the Options — for Word 2010, File > Options > Advanced > Show Document Content section > Show field codes instead of their values check box — don’t forget to turn it off when you’re finished)


  22. Hi guys, let me ask one additional question. Is there any chance to use a styleref in the footer to automatically put a certain text from the header (not from the “regular” document, where Word seems to be searching only) there?? Word does never find a result of the style selected (for example, to make it easy, “Heading1”) if this only appears in the header, but not in the normal text. Any ideas?? Thank you so much!!

  23. Looking for an answer like this for ages!

  24. Hi Rhonda! I have set up a few templates for my office that use this technique. There is one issue that I cannot find the answer to:

    The table (step 2) is a 3-column layout. In the cell that the StyleRef is pulling information from, the entered info often gets pushed to a second line within the cell.

    City of Oceanside Department of

    Users, in an attempt to control how those two lines are split, will hit ‘Return/Enter.’

    City of Oceanside[‘Return/Enter’]
    Department of Recreation

    When they do this, only the second line of the entered info gets displayed in the footer even though both lines within the table are the correct referenced style. Ideally, the two lines would appear in the footer on the same line. I doubt that I can get users to stop pressing ‘Return/Enter’ when filling in this information and was wondering if anyone has a hint/solution/macro that could help? This might be a stretch but do you know if there is a way to set a macro for the StyleRef that eliminates the ‘Return/Enter’ line jump before populating the footer?

  25. Have you tried Shift+Enter to add a ‘soft’ line break?

  26. Thanks for the response, Rhonda. That does work – all the information is translated to the footer (now as a two-line footer.) But I’m hoping that there is some way that I, as the administrator of these templates, can take the solution out of the user’s hands. As much as I hope people would use Word properly and learn the tricks, I doubt they will. If I could program the StyleRef (or maybe a macro?) to automatically do the soft break, that would be ideal. Any hints/tips are greatly appreciated.

  27. This is truly a nice function. However, I have run into a very peculiar issue: my reference only applies to the header on the first page. The second page remains unchanged and with no response to field update. Any suggestions?

  28. Hi Roger

    My guess is that you have ‘different first page’ set in the headers, or you have several sections in your doc and don’t have ‘link to previous’ set. You’ll need to set it up for the header in EACH section.


  29. I have also encountered an issue here . . . . i am trying out the ‘styleref’ field in a company template and am trying to understand how it works. The reference doesn’t always update on every footer – sometimes it will update on page 3, but not page 1 and 2. Then sometimes page 1 will suddenly update whilst navigating the document – but not page 2. There seems to be no consistency either in when it happens, it is random. It will however update on ‘print preview’ but i’d like to know why it isn’t updating in the first place. I have no ‘section breaks’, ‘link to previous’ or ‘different first page’ set. Any advice would be appreciated. Thanks.

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: