Microsoft KB Archive/99954

{|
 * width="100%"|

Macro to Toggle All Document Field Codes On and Off

 * }

Q99954

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows 95, version 7.0

-

SUMMARY
Using the WordBasic macro language, you can toggle all field codes on or off in a document. The following information outlines two methods for setting up a toggle field codes macro.

MORE INFORMATION
Method 1 can be used to toggle field codes on and off by assigning the ViewFieldCodes command to a Toolbar button. Method 2 toggles the ViewFieldCodes in your document and displays a message on the status bar (either &quot;Field Codes On&quot; or &quot;Field Codes Off&quot;).

Method 1 For Word 6.0, 7.0

 * 1) On the View menu, click Toolbars.
 * 2) Click Customize.
 * 3) On the Toolbars tab, in the Categories list box, select View.
 * 4) Under Buttons, click the View Field Codes button ({a}) and then drag it to the desired location on the toolbar.

NOTE: There are several ways to edit the toolbars in Word 6.0 and 7.0. To see all available methods, see your user's guide, or look in Word help under Toolbars.

Method 1 For Word 2.0

 * 1) On the Tools menu, click Options, and select the Toolbar category.
 * 2) In the Tool To Change list box, select a Toolbar button to change.
 * 3) In the Show box, select Commands.
 * 4) Select the ViewFieldCodes command.
 * 5) In the Button list, select a Toolbar button and click Change.

Method 2 For Word 2.0, 6.0, 7.0
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following WordBasic macro toggles all field codes in the current document and prints the status of ViewFieldCodes in the status bar:

  Sub MAIN Result = ViewFieldCodes If Result = 0 Then ViewFieldCodes 1 Print &quot;Field Codes On&quot; Else ViewFieldCodes 0 Print &quot;Field Codes Off&quot; EndIf End Sub For information about how to do this in Word 97, please see the following article in the Microsoft Knowledge Base:

"Q159968 Word 97: Macro to Turn All Field Codes On and Off"