Excel: Determining the Name of the Active Macro

Last reviewed: November 29, 1994
Article ID: Q63954
The information in this article applies to:
  • Microsoft Excel for the Macintosh, versions 2.2, 3.0, 4.0

SUMMARY

If a macro is renamed by the person using it, this can cause problems with such macro statements as ACTIVATE and SAVE.

Although you can use GET.DOCUMENT(1) to return the name of the active document, this method is useful only if the macro sheet is already the active document. If the macro sheet is hidden or if it is not the only document open, there is no guarantee that GET.DOCUMENT(1) will return the macro name.

However, you can use FORMULA.GOTO to activate the macro sheet without knowing the macro sheet's name.

MORE INFORMATION

The following macro is defined as auto_open and therefore will run every time the macro sheet is opened:

  A1: auto_open
  A2: =ACTIVATE(WINDOWS()) ;In case all windows are hidden
  A3: =FORMULA.GOTO(A1)    ;Goes to A1 on running macro sheet
  A4: =GET.DOCUMENT(1)     ;Name of active sheet (this one)
  A5: =RETURN()            ;end macro

The value in cell A4 contains the name of the macro sheet after this macro is run. Because this name is text, it can be used in any subsequent function requiring the macro name. For example:

   =ACTIVATE(A4)

The above function will activate the macro whose name was returned by cell A4.

REFERENCES

"Microsoft Excel Function Reference," version 4.0, pages 172-173

"Microsoft Excel Function Reference," version 3.0, page 93

"Microsoft Excel Functions and Macros," for the Macintosh, version 2.2, page 227


KBCategory: kbusage
KBSubcategory:

Additional reference words: 2.2 2.20 3.0 3.00 4.0 4.00 macrosheet
function command


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 29, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.