Macro to Toggle All Document Field Codes On and Off

ID: 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 "Field Codes On" or "Field Codes Off").

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 "as is" 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 "Field Codes On"
   Else
     ViewFieldCodes 0
     Print "Field Codes Off"
   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


REFERENCES

"User's Guide," version 2.0, pages 723-725

"Microsoft Word for Windows and OS/2 Technical Reference," page 280

"Microsoft Word for Windows Technical Reference," page 103

Kbcategory: kbusage kbmacro

Additional query words: wordbasic toolbar viewfieldcodes word6 7.0 word95 word7 winword winword2 toggle 2.0

Keywords :
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0
Platform : WINDOWS
Issue type :


Last Reviewed: September 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.