WD: WordBasic Macro to Test for an Existing Style Name

Last reviewed: November 17, 1997
Article ID: Q117826
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY

When you write macros in Microsoft Word, you may need to test for the existence of a style name before modifying or deleting the style. If your macro does not check for the existence of a style before attempting to modify or delete the style, the FormatStyle command may return the following error message:

   This style name does not exist.

MORE INFORMATION

The following WordBasic macro tests for an existing style named "Test." If the style exists, Word deletes the style.

   Sub MAIN
   sStyleName$ = "Test"
   If StyleDesc$(sStyleName$) = "" Then
    MsgBox sStyleName$ + " does not exist", "Style Name"
   Else
    FormatStyle .Name = sStyleName$, .Delete
   End If
   End Sub

For more information about how to do this in Word 97, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q158847
   TITLE     : Word 97: Macro To Test For An Existing Style Name

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, pages 706-707


Additional query words: WordBasic delete style FormatStyle
Keywords : kbmacroexample macword winword word6 word7 word95 kbcode kberrmsg kbmacro kbprg
Version : MACINTOSH:6.0,6.0.1,6.0.1a;WINDOWS:2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


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: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.