WD: Macro to Test for an Existing Macro Name

Last reviewed: July 30, 1997
Article ID: Q99958
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a

SUMMARY

When you write macros in Word, it may be necessary to test for the existence of a macro before running the macro with the WordBasic ToolsMacro statement. If your macro does not check for the existence of a macro, you may receive one of the following error messages:

   There is no such macro.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following WordBasic macro uses the IsExecuteOnly function to test for an existing macro named "Test" in the global template file, Normal.dot:

   Sub Main
      On Error Goto errors
      MacroName$ = "Test"
      exe = IsExecuteOnly("Global:" + MacroName$)
      ToolsMacro .Name = MacroName$, .Run      'Run global macro if it exists
   errors:
      If err = 511 Then
         MsgBox Chr$(34) + MacroName$ + Chr$(34) + " macro does not exist"
   End Sub

To test for the existence of a template-based macro, change the word "Global:" to the name of the template in the above macro. For example:

   exe = IsExecuteOnly("Memo2:" + MacroName$)

REFERENCES

"Using WordBasic" by WexTech Systems, Inc., and Microsoft Corporation, page 246

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: 2.0 2.0a 2.0a-CD 2.0b 2.0c word6
winword 7.0 word95 word7 winword2 6.0 ToolsMacro run macro exist template
global error 511
Keywords : kbmacroexample kbmacro
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a
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: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.