They are classified as Document Information fields. They can be inserted through Word's interface as well. In its simplest form this will display the page number, numbered from the beginning of the document. You can format any of the page number to display in Roman numerals upper- or lower-case , Arabic numerals, or as text. More on that later. You can restart the page numbering anywhere you want; doing so will insert a new Section if you are not already at the start of a new Section.
If placed in a header or footer it shows the section in which the page starts. There can be more than one section on a page. A document must have at least one Section and can have many. It is often used to number Appendices in a document. See Page Numbering on Greg Maxey's site for a workaround that allows the user to have both the Section pages numbers and of the Document page numbers in the same spot. This field also updates instantly. In Ribbon versions of Word, a Cover Page can be inserted in a document.
In Word this will be counted in all of the pagination fields. See Cover Page Anomalies. All of the pagination fields can be formatted using field switches. In any version you get a dialog to format page numbers that lets your restart page numbering or change the way the numbers are displayed.
The dialog from Word is shown below. This dialog lets you select a format as well as include a Chapter number based on a style to start a chapter. When doing chapter pagination, one normally begins the chapter with a new Section and restarts the pagination at the beginning of the section. You can only restart pagination with a section break. Although this dialog gives a number of formatting options, at this point, I will discuss field switches instead.
That brings up a dialog like the following:. You can use any of the numeric field switches with your pagination fields. For the DocProperty Pages field you would need to edit the field code manually; the dialog will not insert the switches. Field Result. These switches work in any field that has numeric information. More about using calculation fields and page fields: How to control the page numbering in a Word document. Those fields pay attention to the format set in the page number format dialog.
The MacroButton field is a field developed in early versions of Word pre-Windows. The name comes from the ability to trigger a macro. It was early used to insert dummy text for typing and can still serve that function well, without any macros.
It continues to work, well, in Word DisplayText - text that acts as the "button" for the macro and is displayed in your document. Note that there are no quotation marks used in this field. DisplayText can be any text you want but will not wrap to a new line. There are limits on length. Instead of the DisplayText you can insert an inline picture or icon to act as a visual button for your macro. See below , though for images. The text in a MacroButton field prompt cannot be longer than a single line between the left and right indents for the paragraph.
You can shrink the font size of the prompt text to fit more words on that single line. Clicking on a MacroButton field will select the field. Double-clicking on one will activate a macro if there is a macro designated.
You can change this behavior to make the macro activate on a single click as well. You can use the first behavior selecting the field to make simple click-and-type prompts. If you look at many of the templates that come from Microsoft with Word, you will find places that say something like "[Click here and type]. Often, this is exactly what you want for a simple prompt. What you are seeing is a simple implementation of the "MacroButton" field. This use of the macrobutton field is the forerunner of Content Controls.
To insert a MacroButton field like this in your document type it then make it a field. Pressing F9 will update it to the field display of DisplayText. You must create or edit the field manually to get colors or other formatting in your prompt text that will disappear when the user actually uses it and types.
Inserting a MacroButton field like this in your document using the Field insertion dialog is a bit more involved:. The " prompt " is whatever prompt text you want. This can be "[Click here and type]" or the text that will usually be just fine but which the user might want to change. Note that if there was an available macro with the name "nomacro" that macro would be run by this field. Any name that does not indicate an available macro will give the same result, that is, the entire field will be selected when clicked on as always happens with a MacroButton but since no macro can be found, the result is selected text.
If you want to format your prompt text, you need to do that by revealing the field code and editing. As is the case with other fields, the F11 key will take you to the next field, selecting that field.
When you use macrobutton fields as prompts, you may want to put an instruction in your documents to use F11 to go to the next field. I do this putting the instruction in blue or red text and a different font in a textbox formatted to float in front of text. The textbox is formatted to have no lines and no fill.
The text in the textbox is formatted as hidden so it should not print. I have this textbox as an AutoText entry in my developer's template so that I can insert it easily when I prepare a new template. Below is an example of how a Macrobutton Prompt appears in a document. Screenshot The field code for this prompt is:. When you click on it, all is selected.
The first paragraph shows the prompt as displayed on the page. The second shows the prompt after it has been clicked on before typing; the third shows that the prompt colors do not show up in the text after the user types. You can download a free Add-In that gives you a dialog box below to add a MacroButton prompt to your document where you want with a choice of colors for the prompt text.
Dialog box from Add-In. Instead of simply being a prompt for typing, this MacroButton field will run a macro if double-clicked. This can be altered to a single click using VBA. Instead of NoMacro, simply type the name of the macro. When inserting the field, you can click on the Options button and you will be given a list of available macros possibly quite a long list from which to select.
Where it says "Macros defined in active document" a more accurate caption would be "Macros available to active document. Note that the MacroButton field is selected when it is clicked or double-clicked. You may want to have your macro collapse the selection at some point so that your MacroButton field won't be inadvertently deleted. The language for this is:. Note also that a macro button prompt will print as ordinary text. It is the field result. Because of this, it is often easier to use a custom toolbar with a button on that toolbar.
The toolbar will not print. MacroButton Fields can be used in Protected Forms and will be active even in a protected portion of the document.
They are often used in such forms as a replacement for hyperlinks since regular hyperlinks are inactive in the protected portion of a form. A simple example of macrobuttons can be found in the CheckBox template. It is possible to use one macro that responds to the contents of the field to change what the macro does. The same technique can be used with just the display text of the MacroButton field.
The macro is:. Fields 1. The field is:. This can be used to construct a list of templates in the Workgroup Templates folder as macrobuttons. When you double-click or single-click as shown below on the macrobutton, the macro creates a new document based on the named template.
A single macro decides which template to open based on the template listed in the macrobutton field. Collapse Exit Sub ' End Sub. To me, double-clicking on a button is counter-intuitive. To make a macrobutton respond to a single click to run a macro the following VBA code has to be active:. This has to be run before the user tries to click on the button. It can be in an AutoOpen or AutoNew macro in the template which contains the macrobutton or in an AutoExec macro in a global template.
Explaining these gets beyond the scope of this article; see Template Basics for more. In a document that has been "protected" as a form in Word, hyperlink fields don't work, but macrobutton fields do work. You can use a macrobutton for a hyperlink to an external document or web page and even format it to look like a hyperlink in a protected document.
It is more work than merely inserting a hyperlink, though. You can also use a macrobutton to link to an internal bookmark with reservations, see end of this section. When you protect your document your pseudo-hyperlink should work fine. Remember to set the ButtonFieldClicks to 1.
Also, the mouse pointer will not change to a little hand when passing over your pseudo-hyperlink - but we can't have everything, can we?
If you would like some pre-written code for your hyperlink macrobutton, you can download HyperJmp. They show how to use a single macro for all your hyperlinks in the document. When the target of the link is within the protected form it doesn't work quite so well. It will jump to the field addressed by your bookmark if your bookmark is for a formfield, otherwise to the field following your bookmark.
If there is no field following your non-field bookmark, it jumps to the first field in the document. Note that fields inserted with the Forms toolbar automatically have a bookmark assigned. You can change that bookmark in the field's properties. Thanks to Marcy T. For more on protected forms, follow the links in my web resources page , especially those to Dian Chapman's excellent series of articles.
Note the checked box by "For Review. The prompts for user input are MacroButton fields not associated with any macro. A dummy name of "NoMacro" is inserted but the purpose of the field is to display the prompt. Both of these use the property of MacroButton fields to select the entire field when clicked on. The display text for the checkbox fields is the unchecked or checked box.
If there were an active macro named NoMacro or nomacro these MacroButton fields would call that macro! The name of the macro called by the unchecked Urgent checkbox is "CheckIt.
All you see is the display text - the checked and unchecked boxes. See Checkbox Add-In for samples. An image does not work well as a prompt in document templates formatted as. See this post on the Microsoft Answers forum.
The image is selected, not the field. If the image is deleted by the user and the user types, that typing becomes the prompt for the field. Clicking or double-clicking on the field will not run a macro. If the same document is saved in. The screenshot below is from a document in. Here is a screen shot of the same thing, except the same document has been saved in. In the. If the user types anything, the image is deleted, the field is deleted, leaving only the typing. When in.
No macro is run. If the image is deleted by the user and the user types, what the user types becomes the new MacroButton field prompt!
If there is no image, or if the user clicks on a text prompt included with the image, the field is selected, including the image, and replaced by typing. Note the image moves in front of the text even though formatted to be inline with text. If there is a macro, it will not run in this condition. Shows what it looks like when the space after the text is clicked on or the field is entered using the F11 next field function key.
When this is done, if there is a macro, it will run. In Word and later when you click on the image, any text typed is added to the MacroButton Field prompt text.
If the field itself is selected or you click in the area following the image, the field is replaced by typing. In this second instance, if there is a macro, it is run first. If the same fields are saved in a. See Greg Maxey's page on Toggle objects for some ways to get Word to respond to images in macrobutton fields. One method is with spaces, another is with the IncludePicture field inserting the image.
The second suggestion comes from Doug Robbins. An example using the IncludePicture field:. Using that construction, the image is selected with the macrobutton and replaced by typing. Macrobutton prompts and text content controls can have a similar appearance in a document. Here is a screenshot showing plain text Content Controls and a MacroButton field prompt.
Both have the placeholder text formatted using the PlaceHolderText style. Both select the entire contents when you click in them. When not selected, they can be indistinguishable to the user. The color of placeholder text can be edited when you create them and can be something that is very different from the color of the text that will be typed. Unless formatted to delete the content control when edited, the content control will remain with edited text.
The macrobutton field will be replaced by typing. MacroButton field prompts will work in versions of Word that do not work with Content Controls as well as those that do. This includes Mac versions. This is not true of a hyperlink field. Search Usersguide to Microsoft Word using Google. I'm not sure why it is an improvement over a Hyperlink.
A double-click will take the user to the bookmark location. If the bookmark contains something, it will be selected. The GoToButton field responds to the options. ButtonFieldClicks setting discussed earlier in MacroButton fields. That is true only if the place is identified by a bookmark.
Here is a screenshot of the Insert Field dialog. When placed in a header or footer, the StyleRef field updates instantly with any change in the source text.
When placed in the body of a document, it updates the way other fields in the body update. Generally a print preview will update fields but not always. Here is the Microsoft Reference page for the StyleRef field. StyleRef field gives an Error Message "Error! No text of specified style in document. This is pretty self-explanatory. The specified style must be in use somewhere in the document.
This one is a bit more rare. It is telling you that the field, itself, is in the specified style. It is trying to reference itself. StyleRef does not show anthing - blank! This indicates that the StyleRef field is referring you to blank text.
In the case of a paragraph style, an empty paragraph formatted in the style. In the case of a character style, a space formatted, by itself, in the style. StyleRef field is showing text from previous pages or following pages and you do not want this.
This means that there is nothing in the specified style on the current page. If you would prefer that it show nothing, create a blank in the specified style. See 2 above. Do you want your headers or footers to reflect the content of the page, or change from Chapter to Chapter? Are you trying to get dictionary style fields Krofta - Lamb listing the first and last entry on your page?
If that is what you are trying for, the following will work: Put your last name field or whatever it is you are trying to capture in a particular character style in your primary merge document. The character style does not need to look any different from surrounding text but it can look different. If the StyleRef field gives you nothing but does not give an error, that means that the specified use of the style has no text. Look in help for "dictionary-style headers.
You are using the style as a tag rather than as a way of formatting. Remember, this new style is a character style rather than a paragraph style. This is especially useful when you have something on the first page of a document which, if changed, should be reflected in continuation page headers or footers. Examples: the addressee name, the subject, the date. Barnhill, MVP If you are doing this in a mail-merge, you may have to insert the header after you do the merge.
Try inserting it before you do the merge, if that doesn't work, then try after. I haven't tried this with a mail merge but it should work. After you get results, please share them by letting me know so I can update this. If your have a single word or a phrase in a document marked in the character style "MyStyle" that word or phrase will be reflected in this field's results, instantly. This updates in headers and footers as well as in the body when the marked text is changed.
It is much more robust than bookmarks which are easily deleted by accident. Either a character style or a paragraph style will work with the StyleRef field. The style does not have to change any formatting - it can just serve as a marker for the field. In the tutorial the styles used do have formatting functions as well -- primarily the paragraph spacing and the designation of the following style. Note: it has been observed that if there is a bookmark with the same name as the reference style it can cause problems.
See this forum thread. If you use a StyleRef field and there is no text in that style anywhere in the document, you will get an error message. That probably is not what you want. You can use a conditional IF field to screen the error message.
The following nested field displays nothing unless there is something in the named style. If something is present in that style, it gives you the text set in the style as well as extra comment text in the field. If you do not need the extra comment text, do not put it in the field. Note that this structure cannot be created using Word dialogs; you must edit the field code itself in the document.
This coding came from responses to a Word Answers forum question. StyleRef Field documentation BetterSolutions. StyleRef Field documentation Microsoft.
Note, if the StyleRef field finds text that has been formatted as hidden, it will display blank. It will not search for the next displayed text. If your selection is in the main story, the content in e. Also, shapes text boxes, circles, rectangles, etc. There are several different layers, or stories, in a Word document, actually a total of 17 different types as you will see below.
There may not be content in every layer, though. Each story in a Word document may contain objects belonging to other stories. Therefore, you may need to access the objects like opening a Chinese box. Example : In order to update fields in shapes in the headers of a Word document in VBA, you first need to access the correct type of header.
There are, as you may know and as you can also see in the overview of story types below , not only one header story but three: even pages, first page and all other pages. All shapes that can include text can also include fields — and as fields elsewhere in a Word document, fields in shapes also need to be updated. Therefore, it is useful to understand how Word treats shapes like text boxes, circles, rectangles and other drawing objects with text.
If you right-click a shape that does not have any text, you should see the Add Text command in the context menu if the type of shape can include text.
If you try to insert a text box or another shape in e. Figure 2. Message — you can't put drawing objects in all areas of a Word document. As explained above, the content in a Word document is spread across a number of layers, called stories in VBA. The table below lists the names and numbers of the different story types in VBA. The rightmost column includes information about how the story is related to the content in the Word document.
Some warm fields are updated automatically when the source changes. Warm fields that are not updated automatically by Word can be updated manually. You can use different methods as described below.
Note that this method only works in the area of the document where the selection is. If there are fields in e. TIP : If you experience that one or more cross-reference fields do not update as expected, see the article Cross-reference Problems - Troubleshooting. This method is not sufficient if other kinds of fields need to be updated.
You can update all fields anywhere in the document in one operation using a macro made for that purpose. This is most often the smartest method, at least in documents where fields may be spread across many layers in the document.
If you make an update field macro available via the Quick Access Toolbar QAT or a keyboard shortcut, it takes only a single click to update all fields in the entire document. I have created a ready-for-use macro that updates all fields in the document no matter where they are found.
You can get the Update Fields macro here. If you turn ON the option Update fields before printing , all fields in the document will be updated when you print. See the illustration below. Note that this option is a global Word option that applies to the individual user's Word. It is not stored in the individual document.
This means that you cannot rely on all users having this option set the same way unless it is managed by e. In general, a document you print should reflect the actual content of the document. This also means that you would most often want fields to be updated when printing. There may, however, be situations where you want to print a document without fields being updated.
Maybe they are not set up correctly for the purpose. I have seen examples where more or less random fields had been copied from other documents without the user updating them in the new document. The fields were indeed wrong in the context. When the fields were updated during print, they revealed undesired field results. Instead of fixing the fields, the user wanted to prevent them from being updated when printing.
Instead, the problem should be solved by correcting the fields. There may be situations when you want to prevent the result of a field from being updated. You can obtain this by locking the field. Locked fields will not change even if you update fields:. Another way of retaining the current field result is to convert the field to normal text. You can insert the entire document or a bookmarked portion of the document. For example, cross-reference fields and other types of fields could be found.
A field with the following field code will insert the content from the document "My Document. That is the default behavior. Let's say a cross-reference field in the source document shows "My heading text". However, the heading it points to has been changed to "My new heading text" without updating the cross-reference field. You can get my Update All Fields macro here. See the Microsoft article List of field codes in Word for information about the individual types of Word fields, their syntax and how to use them.
The Microsoft support article Some fields are updated while other fields are not lists fields that are updated automatically or updated e. However, the lists don't seem to be complete according to my experiments.
In the lists above, you will see that more fields are listed in those categories than in the Microsoft article. By default, Word has a number of keyboards shortcuts related to fields. Knowing those shortcuts can save you a lot of time.
See my article about useful shortcuts related to fields. For details about cross-reference fields, see my article How cross-reference fields in Word work on my website wordaddins.
In case of problems with cross-reference fields not being updated as expected, see my article Cross-reference Problems - Troubleshooting. Updating Fields in Word — How it Works. Quick Navigation Fields in headers and footers of documents. But that only seems to happen if you, after the bookmark change, open the Properties dialog box and click OK — and then updated fields. There are also other important limitations to the bookmark content shown in such DocProperty fields: Only plain text is included in the field result and only up to characters no matter what is included in the bookmark.
This means that you cannot use Link to content to have DocProperty fields show longer texts or non- textual content like images or tables.
If a document contains custom document properties added via the built-in Properties dialog box and if Link to content is turned on, DocTools DocPropertyManager will detect this in case you attempt to modify the property. You will then be asked whether you want to modify the property via the built-in dialog box instead. The built-in Properties dialog box cannot be resized. The dialog box for creating and editing custom document properties in the DocTools DocPropertyManager add-in is flexible and has room for longer names and values.
In addition, it lets you sort the properties alphabetically. Also, a Filter field makes it fast to find a specific property in the list. When you click a property in the list, you will see information about how many DocProperty fields are found in the document that refer to that property. You could as well ask: How to modify document properties in Word. The terms edit and modify mean the same in this situation. You can edit modify the value of a custom document property. The built-in functionality in Word does not let you change the name of a custom document property.
Once you have added a custom document property, you can edit its value but you cannot change the name using Word's built-in features. The only way to change the name of a custom document property is to delete the old property and add a new one. Otherwise, such field will show Error! Unknown document property name once fields have been updated.
If you use Word's built- in feature, you must change the field code in DocProperty fields if you have deleted an old document property and added a new one to change the name. As opposed to the cumbersome procedure needed for renaming a custom document property using Word's own features, the DocTools DocPropertyManager add-in lets you rename any existing custom document property simply by changing its name. DocTools DocPropertyManager will automatically do all the work for you, including correcting the field code in any DocProperty field that refers to the renames document property.
To insert a document property in Word, you must insert a field of the type DocProperty. Using the built-in functionality, you can insert a DocProperty field either via the Field dialog box or by typing the field code manually. Both methods are described below. The Field dialog box ready for inserting a DocProperty field. Personally, I always turn the option off since it may result in undesired formatting. For example, a field with the switch may appear with bold text if the field has once shown an error.
If special formatting is desired, it is more stable to add relevant switches for the formatting directly. DocProperty field showing field code and field result.
If you know the name of the document property you want to use, it is faster to type the field code manually than using the Field dialog box. The same is true for many other types of fields in Word. If a DocProperty field refers to a property name that does not exist in the document, the field will show an error when fields are updated: Error! Unknown document property name.
See the illustration below:. Example of DocProperty field showing an error because it refers to a property that does not exist. The error test will be shown in the language of your Word. The error will occur if you have deleted the custom document property to which the field refers. The error will also occur if you insert content that has been copied from another document and if that content includes DocProperty fields that refer to property names that don't exist in the target document.
The DocTools DocPropertyManager add-in lets you easily add all missing custom document properties, if any, by the click of a button. Note that DocProperty fields do not update automatically. If the value of one or more properties referred to in DocProperty fields has been changed, you need to update the fields to reflect the changes.
For detailed information about how all types of fields are updated, see my article Updating Fields in Word — How it Works. As mentioned above, custom document properties can be of the types Text , Date , Number and Yes or No. Below, you will find a description of each type.
Text is the most commonly used type. The other types, Date , Number and Yes or no require specific values and in the document, such fields will not always insert a value that is identical to the value you specify in the Properties dialog box. Therefore, you must make sure that you fully understand how the values of those types work before you start using them. I use custom document properties and DocProperty fields in the main part of the many Word documents I work with.
I always define custom document properties of the type Text. DocProperty fields that insert a Text property, inserts precisely the text you specify as the value of the property. Most often, you can use the type Text for all DocProperty fields. The value can include max. The built-in functionality only lets you enter plain text as the value, without any paragraph breaks or manual line breaks.
You must enter a value in a date format that matches the definition in the regional settings on your PC. You may need to experiment since the language settings also influence the way Date properties work. In case of a standard Danish setting, you can, for example, use the syntax dd-mm-yyyy, e.
A DocProperty field in the document may not always show the date as it appears in the value you specify. You may instead use the type Text. This way, you can enter the date value precisely as you want it to appear in the DocProperty fields in the document. You must specify a number, either an integer or a decimal number. The decimal symbol to use depends on the regional settings on your PC.
If the decimal symbol is a period you can, e. A DocProperty field in the document will show the specified value. You may enter a number value with a thousands separator but Word ignores the separator in the field result.
When you insert DocProperty fields, the value in the document will only be 'Y' for yes and 'N' for no. These code samples may help you create useful macros. In order to create solid VBA code, you will need to add error handling to handle the types of errors that might occur.
The code samples below do not include such error handling. Below are examples of VBA code to edit each of the standard document properties found on the Summary tab of the Properties dialog box. By using names from the wdBuiltInProperty enumeration , you are sure to use correct names that will work in any language version of Word. Each property also has a number that can be used but your VBA code is much easier to understand if you use the names.
Note the comments after each of the listed properties — some are not supported in Word even if they are in the list. Examples of VBA code for editing the values of the standard properties in the active document found on the Summary tab of the Properties dialog box:. If you are editing two or more values, you should use With and End With as shown below:. The VBA code below adds a custom document property in the active document, with the name "My property", link to content turned off, type "Text" and value "My property value":.
For more details about the data types, see About the different data types of custom document properties. The VBA code below changes the value of a custom document property named "My property" to "My new property value":.
The VBA code also works if you leave out ". Value" since. Value is the default property. However, I recommend always adding the property.
It makes the code easy to read and you don't run into problems. The example below has left out the default property. Value not recommended even if it works :. The new value you assign must match the type of custom document property. For example, you can only assign the value in the example above if the type of custom document property is Text.
If you assign a value that does not match the type, a run-time error occurs, saying "Type mismatch". The VBA code below inserts a DocProperty field at the selection, referring to a custom document property named "My property".
If no document property with the specified name exists, the field will show an error. The double quotation marks around "My property" are needed to have quotation marks added in the field code. There are other ways of adding the quotation marks, e.
In the general help on Word, you can find information about the different types of switches that can be used with specific fields. The fastest way to find this information is often to search using your preferred browser.
In documents with fields, it is important to be able to distinguish fields from normal text so you don't accidentally change a field result by manually modifying its result. If you manually modify a field result, the change will disappear the next time the field is updated unless the field has been locked. With field shading on, all fields are shown with gray shading on the screen.
The gray shading is only visible on the screen in Word — it does not print and it is not visible in PDF. For information about keyboard shortcuts related to fields, see my article Word Fields — Useful Keyboard Shortcuts.
Did you know that
0コメント