WD2000: Incorrect Formatting in Index or Table of Contents

ID: Q204433


The information in this article applies to:
  • Microsoft Word 2000


SYMPTOMS

When you apply direct (or manual) formatting, (for example: bold, italic, or underline), to text that contains either an XE or TC field, the direct formatting may be carried over to either the index or the table of contents field results.


WORKAROUND

Use one of the following methods to work around this problem.

Method 1: Remove the Direct Formatting Manually

Select the XE or TC field and press CTRL+SPACEBAR. This forces the character formatting to return to the default of the current style.

To select an XE or TC field, follow these steps:
  1. On the Tools menu, click Options.


  2. On the View tab, click to select All and then click OK.


  3. Select the XE or TC field from which you want to remove the direct formatting.

    NOTE: Your XE or TC field should look similar to one of the following examples:


  4. {XE "text"} or {TC "text"}
  5. With the XE or TC field selected, press CTRL+SPACEBAR.


  6. Repeat steps 3-4 for each XE or TC field that you want to remove direct formatting from.


  7. Update your table of contents or index. To do this, select either the table of contents or index and press F9.


Method 2: Use a Macro to Remove the Direct Formatting from Index (XE) Fields

Microsoft provides programming examples 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. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

For more information about using the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
Q212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

Use the following macro to remove the direct formatting applied to each of the XE fields and then update the index:

Sub ClearXEFormats()

   ' Turn the Show All option on.
   If ActiveWindow.View.ShowAll = False Then
      ActiveWindow.View.ShowAll = True
   End If

   ' Start at the top of the document.
   Selection.HomeKey Unit:=wdStory, Extend:=wdMove

   ' Find the Index Entry fields.
   With Selection.Find
      Do While .Execute(FindText:="^d XE", Forward:=True, _
      Format:=True) = True
         ' Reset the font selections.
         Selection.Font.Reset
      Loop
   End With
 
    ' Start at the top of the document.
   Selection.HomeKey Unit:=wdStory, Extend:=wdMove
 
    ' Turn the Show Field Codes option on.
   If ActiveWindow.View.ShowFieldCodes = False Then
      ActiveWindow.View.ShowFieldCodes = True
   End If
 
   ' Find the Index field.
   With Selection.Find
      Do While .Execute(FindText:="^d INDEX", Forward:=True, _
      Format:=True) = True
         ' Reset the font selections.
         Selection.Font.Reset
      Loop
   End With

   ' Turn the Show Field Codes option off.
   If ActiveWindow.View.ShowFieldCodes = True Then
      ActiveWindow.View.ShowFieldCodes = False
   End If

   ' Turn the Show All option off.
   If ActiveWindow.View.ShowAll = True Then
      ActiveWindow.View.ShowAll = False
   End If

   ' Move the insertion point to unselect the document text.
   Selection.MoveRight

End Sub 

Method 3: Use a Macro to Remove Direct Formatting from Table of Contents Entries (TC) Fields

Use the following macro to remove the direct formatting applied to each of the TC fields, and then update the table of contents:

Sub ClearTCFormats()

   ' Turn the Show Field Codes option on.
   If ActiveWindow.View.ShowFieldCodes = False Then
      ActiveWindow.View.ShowFieldCodes = True
   End If
   
      ' Turn the Show All option on.
   If ActiveWindow.View.ShowAll = False Then
      ActiveWindow.View.ShowAll = True
   End If

   ' Start at the top of the document.
   Selection.HomeKey Unit:=wdStory, Extend:=wdMove

   ' Find the Index Entry fields.
   With Selection.Find
      Do While .Execute(FindText:="^d TC", Forward:=True, _
      Format:=True) = True
         ' Reset the font selections.
         Selection.Font.Reset
      Loop
   End With
 
   ' Start at the top of the document.
   Selection.HomeKey Unit:=wdStory, Extend:=wdMove

   ' Update the TOC field in the entire document.
   With Selection.Find
      Do While .Execute(FindText:="^d TOC", Forward:=True, _
      Format:=True) = True
         ' Reset the font selections.
         Selection.Font.Reset
      Loop
   End With

   ' Turn the Show All option off.
   If ActiveWindow.View.ShowAll = True Then
      ActiveWindow.View.ShowAll = False
   End If

   ' Turn the Show Field Codes option off.
   If ActiveWindow.View.ShowFieldCodes = True Then
      ActiveWindow.View.ShowFieldCodes = False
   End If

   ' Move the insertion point to unselect the document text.
   Selection.MoveRight

End Sub 

Additional query words:

Keywords : kbdta kbmacroexample kbwordvba kbfield wd2000 kbformat
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


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