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



The information in this article applies to:

  • Microsoft Word 2000

This article was previously published under Q224017

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: NOTE: If you reached this article by clicking the Web Info button in an error message, you already have Customizable Alerts enabled.

THINGS 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.
For additional information about deleting unused styles, please see the following articles in the Microsoft Knowledge Base:

189297 WD2000: Sample VBA Code to Delete Built-In Style

193536 WD2000: How to Remove Unused Standard Styles from Document


Modification Type:MinorLast Reviewed:12/2/2005
Keywords:kbprb KB224017