WD: Macro to Test for an Existing Macro NameLast reviewed: July 30, 1997Article ID: Q99958 |
The information in this article applies to:
SUMMARYWhen 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 INFORMATIONWARNING: 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 SubTo 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |