Tuesday, July 16, 2024

Microsoft Word: Working with Field Codes

Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Some of Word’s most powerful features are hidden from view, and one of these is field codes. While you may have encountered field codes when using mail merge, that’s not the only task you can accomplish with field codes. In this article we’ll look at how you can use field codes by themselves and in conjunction with bookmarks to create smart Word documents.

Let’s see a field code at work. To begin:

  • Choose Insert > Field
  • From the Categories list choose Date and Time
  • From the Field Names list choose Date
  • Select the date format you want from the Field Propertieslist
  • Click OK

What you see on the screen depends on your particular Word setup. You may see today’s date formatted in the style that you selected, or you may see a field code on the screen that looks something like this:

{ DATE  @ “dddd, MMMM dd, yyyy”  * MERGEFORMAT }

Click-Here field screenshot
A Click-Here block can be created using the MacroButton Word field.
(Click for larger image)

If you see the date rather than the field code, press the Alt + F9 keyboard buttons simultaneously to toggle between displaying field codes and the field code results. The field code you see is created inside a set of curly braces.

While it appears that you could type the curly braces on the keyboard to create your own field codes this is not the case, and these braces are special characters that can be inserted only by pressing the Ctrl + F9 key combination.

Another handy field code keyboard shortcut is Shift + F9 – use this when you are positioned inside a field code to toggle between displaying the field code and displaying the results for this field code only.

To manage how Word displays field codes, choose Tools > Options > View tab. You can select whether field codes show in the document or not (disabling this is the preferable setting) and when to shade the fields: Never, Always or When Selected. Selecting Always or When Selected may assist you in getting started with field codes and the shading won’t display when you print the document.

Click-Here Blocks

One way to harness field codes to help create smart documents is to use them for Click-Here blocks. You click on these markers in your document to enter text. These boxes help ensure that text is positioned correctly, and they provide a useful prompt for the user. To make one

Click an area in the document where you want people to type some text, and

  • Choose Insert > Field
  • From the Categories dropdown list choose Document Automation
  • From the Field Names list choose MacroButton and click the Field Codes button in the bottom left corner of the dialog

In the Field Codes area you should see the word MacroButton followed by some text. Remove the text and replace it with the following text so the Field Code looks like this: MACROBUTTON ClickHere [Type Recipient’s name in here]

Now click OK.

ASK field screenshot
The ASK field sets up the bookmark you will use for entering text.
(Click for larger image)

If you see the field code, press Alt + F9 so that you see just the prompt on the screen inside its square brackets. You can save this file either as a regular document or as a template.

Open the file or create a document based on the template and ‑ to see how the click-here block works ‑ click the prompt and type some text. When you do this, the field code disappears to be replaced by the text that you typed.

The basis for this click-here block is the MacroButton field code that is typically used to run a macro. However you can trick it into acting as a click-here block by typing a macro name that does not exist. The text you place in the square brackets is the prompt that will show on the screen. The square brackets are optional but they make the click here block look more professional.

You can create multiple click-here blocks in one document – use the same macro name and just change the prompt for each of them.

Combining Field Codes and Bookmarks

You can combine field codes with bookmarks to automatically enter text into a document. Here’s how to create a solution that prompts people for their name and then inserts it into two places in a document.

  • Start with a new document and choose Insert > Field
  • From the Categories list choose Mail Merge
  • From the Field Names list choose ASK
  • Type “Your Name” in the Promptbox
  • In the Bookmark Name box type YourName.
  • Select the Default Response to Promptcheckbox and type “Type your name in here”
  • Click OK

You should now see a dialog on the screen prompting you to type your name. Click OK to accept this ‑ do not type anything into the box at this stage.

REF field screenshot
Use the REF field to enter data that the user types in response to the ASK question.
(Click for larger image)

The bookmark reference “YourName” is the key to entering your name into the document.

  • Click on the place in the document where you first want your name to appear, and choose Insert > Field
  • From the Categories list choose Links and References
  • Click the REF field in the Field Nameslist
  • Next click the Field Codes button and after the word REF type YourName
  • Click Hide Codes and then from the Format dropdown list choose Title Case
  • Click OK

You should now see the text “Type your name in here” in the position that you placed the REF field code.

Repeat this process and create a REF field at each position in the document where your name should appear. Create each REF field exactly the same way as the previous one using the YourName bookmark, but you can choose different formatting if you like. When you’re done, save the document as a regular document or a template as desired.

Update field screenshot
When you update field codes in the document, the ASK field prompts you for information.
(Click for larger image)

To see how this feature works, open the document and:

  • Choose Edit > Select All or press Ctrl + Ato select the entire document
  • Press F9to update the fields in the document. This triggers the ASK field which displays the dialog on the screen prompting you to enter your name.
  • Enter your name and click OK

In each place where you placed a REF field you should now see your name appear.

If you need multiple pieces of information entered into a document in lots of different places, create ASK fields for each of them and place a REF field in each position you need to insert the data into the document.

The only proviso is to ensure that each ASK field has a different bookmark name and that the REF field refers to the bookmark name for the particular data you want inserted at that point in the document.

These examples demonstrate a few ways that Word field codes can help you automate document production and help ensure that data entered into your documents is consistent throughout.

Helen Bradley is a respected international journalist writing regularly for small business and computer publications in the USA, Canada, South Africa, UK and Australia. You can learn more about her at her Web site, HelenBradley.com

This article was first published on SmallBusinessComputing.com.

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Similar articles

Get the Free Newsletter!

Subscribe to Data Insider for top news, trends & analysis

Latest Articles