The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Using Fields in Microsoft Word – a Tutorial in the Intermediate Users’ Guide to Microsoft Word

Posted by jpluimers on 2023/09/15

This page has a truckload of information, but has a short index and few anchor targets: [Wayback/Archive] Using Fields in Microsoft Word – a Tutorial in the Intermediate Users’ Guide to Microsoft Word.

I found it doing these searches:

I needed them because I misread it at first and replaced { SAVEDATE \* MERGEFORMAT } with { SAVEDATE \* "dd-mm-yyyy" } which resulted in the field to become displayed as needed Error! Unknown switch argument.. and at first thought this might be a Windows versus MacOS thing.

Fixing the error with { SAVEDATE \@ "dd-mm-yyyy" }) almost solved the problem, as the actual format should be { SAVEDATE \@ "dd-MM-yyyy" } (which displays month number instead of minute number).

So I learned that Word date formatting is almost the same as Excel date formatting.

I was specifically looking for these bits (the first luckily has the #Charformat anchor and was immediately followed by the latter):

[Wayback/ArchiveThe Difference Between MERGEFORMAT and CHARFORMAT

When writing fields I seldom use either switch, but when I use one, it is almost always the CHARFORMAT switch. Both keep the formatting when the field is updated.

\* MERGEFORMAT

Word inserts the MERGEFORMAT switch by default when you insert most fields. This switch keeps any manual formatting you apply to the field or part of the field. It is seldom what you want! If to a part of the field, it applies to the position, not the Word.

If you have a field result that is: “please respond immediately” and you Italicize “immediately” If it later changes to “please respond after your board meeting,” “after” will be will be italicized because it is the third word in the field. If the result changes to “please give me a call after you’ve had a chance to study this” the word “me” will be Italicized. This switch has nothing to do with the formatting of the source material. Neither does the CHARFORMAT switch.

\* CHARFORMAT

The CHARFORMAT switch allows you to control the formatting of the entire field result. It sets the format to be the same as the first (non-space) character of the field code itself. To use it, you must be display the field code. Whatever direct formatting you apply to that first character will be used for the field result. I usually format the entire field name rather than just the first character, but this is not required.

{ REF myBookmark \* CharFormat }

MyBookmark = “Hello There!”

Field result: Hello There!

MVP Graham Mayor wrote a macro a while back that I use. It turns off the default insertion of MergeFormat and if you check the box to preserve formatting, it asks you if you want to use the CharFormat switch instead. I highly recommend it. You can download it from [Wayback/Archive] his page.

and (because I needed { SAVEDATE \@ "dd-MM-yyyy" }):

The DATE field and its variations.

The easy way (but probably wrong way for what you want) to put a date in your document is Insert => Date or Alt+Shift+D.

If you don’t check “Update Automatically” it is the same as typing the date yourself. If you do check “Update Automatically” it will update when you print (if you have the setting under printer options as “Update Fields” which is the default). You can manually force an update by putting your insertion point in the date and pressing the [ F9] key.

If you want to put a date in a template that updates to the current date when a document is created based on the template, or want to change the format or do other things with the date field, you want to use Insert => Field => Date and Time instead. Using the options here, you can either pick a format or type your own characters (called a picture) for the format. The options for the type of date include:

{ DATE } – The date you are looking at the document. Always today (although it may not show on screen as today until you update the field).
{ CREATEDATE } – The date the document was created (or saved using Save As).
{ PRINTDATE } – The date the document was last printed.
{ SAVEDATE } – The date the document was last saved.

The above are the field codes that will be inserted for you using Insert => Field => Date and Time without using any options. A “\*MERGEFORMAT” switch is automatically inserted if you check “preserve field format” and means leave formatted the same way the field is formatted. Generally, you do not want to check this box or add this switch. If you want one of these formatting switches, you probably want “\*CHARFORMAT” instead.  This switch formats the field result however the first non-blank character within the field is formatted. As with all fields, you must let Word insert the field delimiter braces { }, you cannot simply type them. See the introductory material in this page.

If you choose options, they can include the following “pictures:”

 Picture  Displayed Date
 \@MMMM d, yyyy  August 1, 2000
 \@MMM dd, yyyy  Aug 01, 2000
 \@MM/dd/yy  08/01/00
\@dddd, MMMM d  Tuesday, August 1
 \@ddd, MMM. d, yyyy Tue., Aug. 1, 2000
 \@MM/dd/yy hh:mm:ss am/pm  08/01/00 10:36:12 PM

example: { CREATEDATE \@ “MMM dd, yyyy” }

The word “picture” in the above table indicates a guide to Word on how you want your field to display and print. (Normally called a “mask” in other programming but Microsoft decided to call this a picture for its own reasons.) If you don’t like the pictures you are offered, pick the one that is closest to what you want and then modify it in the Insert Field dialog box (or in the codes themselves using Toggle Field Codes). For more on “pictures” and formatting dates see: Fields Switches.

For information on calculated date fields and a toolbar button that creates such fields, see: http://www.addbalance.com/word/datefields2.htm.

Remember that fields in headers and footers don’t get updated quite as predictably. They work fine with CREATEDATE but can have the same problem as page numbers (see that topic) with DATE.

–jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.