WD2000: Err Msg: "Run-time error '5122': This style name does not exist."

ID: Q224017


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


ERROR MESSAGE

When you try to delete a style from a document with the use of a Visual Basic for Applications macro, the following error message may appear:

Run-time error '5122':

This style name does not exist.
For example, when you run the following sample macro code to delete the style "BodyTextIndent", the error message may appear.

Sub DeleteBuiltInStyle()

Dim odocStyle As Styles
Set odocStyle = ActiveDocument.Styles

odocStyles(wdStyleBodyTextIndent).Delete

End Sub 
NOTE: Microsoft Office 2000 has built-in functionality that allows you to get more information about difficult-to-troubleshoot alerts or error messages. If you want to enable this functionality for this and other error messages in Microsoft Office 2000, please download the Microsoft Office 2000 Customizable Alerts file from the Microsoft Office Update Web site at the following address:
http://officeupdate.microsoft.com/2000/downloadDetails/alerts.htm
NOTE: If you reached this article by clicking the Web Info button in an error message, you already have Customizable Alerts enabled.


CAUSE

The style you are trying to delete does not exist in the document.


WHAT TO TRY

The style you are trying to delete does not exist in the document.

To avoid receiving the error message when you delete a style from a document, you must first verify that the style has been used in the document.

The following sample Visual Basic for Applications macro determines whether the style (Body Text Indent) is being used in the document and, if it is used, it removes the style. If the style does not exist in the document, no message is displayed.

Sub DeleteBuiltInStyle()
Dim odocStyle As Styles
Set odocStyle = ActiveDocument.Styles

   If odocStyle(wdStyleBodyTextIndent).InUse Then
      odocStyle(wdStyleBodyTextIndent).Delete
   End If

End Sub 
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/refguide/

For additional information about deleting unused styles, please see the following articles in the Microsoft Knowledge Base:
Q189297 WD2000: Sample VBA Code to Delete Built-In Style
Q193536 WD2000: How to Remove Unused Standard Styles from Document
Back to Top

Additional query words: OFF2000

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


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