WD97: Macro to Turn All Field Codes On and Off

Last reviewed: February 11, 1998
Article ID: Q159968
The information in this article applies to:
  • Microsoft Word 97 for Windows

SUMMARY

This article discusses two methods for turning fields codes on or off. The first method adds a built-in button to the Standard toolbar. The second method uses Microsoft Visual Basic for Applications to create a macro that turns all field codes in a document on or off.

MORE INFORMATION

Method 1: Add the built-in View Field Codes button to the Standard toolbar

  1. On the View menu, point to Toolbars, and then click Customize.

  2. Click the Commands tab.

  3. In the Categories list, click View.

  4. In the Commands list, click View Field Codes.

  5. Drag View Field Codes to the Standard toolbar. Release the mouse button when you see a vertical bar indicating the location on the toolbar where the command will be inserted.

For more information about customizing toolbars, click the Office Assistant, type "customize toolbars" (without the quotation marks), click Search, and then click to view the "Add a button to a toolbar" topic.

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Word 97 Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE: Office: How to Add/Remove a Single Office Program or Component

Method 2: Use the ShowFieldCodes property

The following Visual Basic macro uses the ShowFieldCodes property and displays a message in the status bar to indicate whether field codes are on or off.

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided

'as is' and Microsoft does not guarantee that they can be used in
all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

   Sub ToggleAllFieldCodes()
      If ActiveWindow.View.ShowFieldCodes Then
         ActiveWindow.View.ShowFieldCodes = False
         StatusBar = "Field Codes Off"
      Else
         ActiveWindow.View.ShowFieldCodes = True
         StatusBar = "Fields Codes On"
      End If
   End Sub

Method 3: Use the following simpler approaches

The following two macro examples are a simpler approach, however there is no notification of the current field code state provided in the previous example.

Example 1:

   ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes

Example 2:

   ActiveWindow.Document.Fields.ToggleShowCodes


For information about how to do this in earlier versions of Word, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q99954
   TITLE     : Macro to Toggle All Document Field Codes On and Off


Additional query words: word8 word97 8.0 8.0 vb vba vbe
Keywords : kbwordvba kbmacro kbusage
Version : 97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 11, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.