Microsoft KB Archive/109063

From BetaArchive Wiki


Excel: Passing Arguments to a Custom Menu Command

Last reviewed: September 12, 1996
Article ID: Q109063

The information in this article applies to:

  • Microsoft Excel for Windows, versions 4.0 and 4.0a

SUMMARY

It is not possible to pass arguments to a macro that is attached to a custom menu command. Passing an argument to a macro attached to a custom menu command generates the following an error message:

   Can not find macro 'macro_name(argument_1...argument_n)'

This is by design. The second column of the menu definition table is reserved for the name of the macro to be run. A macro name is strictly the text used to refer to the macro, which is why you don't include '()' after the macro name. You cannot add an argument to the macro name because this is not a valid macro name.

NOTE: A macro with () is a valid macro CALL.

MORE INFORMATION

To further illustrate this concept, two scenarios are outlined below. Scenario 1 is the proper method. Scenario 2 generates the error message as described above.

Scenario 1

Macro Sheet:

A1:  =ADD.COMMAND(1,"EDIT",A5:B6)        B1:
A2:  =RETURN()                           B2:
A3:                                      B3:
A4:  CUSTOM COMMAND DEFINITION           B4:
A5:  MY_COMMAND1                         B5: MY_MACRO
A6:  MY_COMMAND2                         B6: MY_MACRO
A7:                                      B7:
A8:                                      B8:
A9:  MY_MACRO                            B9:
A10: =ALERT("HELLO")                     B10:
A11: =RETURN()                           B11:

Scenario 2

Macro Sheet:

A1:  =ADD.COMMAND(1,"EDIT",A5:B6)        B1:
A2:  =RETURN()                           B2:
A3:                                      B3:
A4:  CUSTOM COMMAND DEFINTION            B4:
A5:  MY_COMMAND1                         B5: MY_MACRO("MYTEXT1")
A6:  MY_COMMAND2                         B6: MY_MACRO("MYTEXT2")
A7:                                      B7:
A8:                                      B8:
A9:  MY_MACRO                            B9:
A10: =ARGUMENT("MYTEXT",2)               B10:
A11: =ALERT("HELLO "&MYTEXT)             B11:
A12: =RETURN()                           B12:

KBCategory: kbusage

KBSubcategory:

Additional reference words: 4.00 4.00a




Last reviewed: September 12, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.