XL5: "Cannot Find Macro" Running Macro in Active WorkbookID: Q115905
|
In a Visual Basic macro in Microsoft Excel, if you activate a sheet
in another workbook, and you use the Run method to run a macro in the
activated workbook, such as SHEET1!Auto_Activate, you receive the following
error message:
Run-time error '1004':
Cannot find macro 'SHEET1!Auto_Activate'.
This error occurs if you use the Run method to run a macro contained
in another workbook, and you do not include the workbook name with
the name of the macro you want to run. The error occurs because, by
default, the Run method tries to find the macro name you specify
within the workbook that contains the code that is running, not the
active workbook.
For example, if you run a macro in BOOK1.XLS, that activates a sheet
in BOOK2.XLS, and uses the Run method to run a macro contained in
BOOK2.XLS, you must include the book name BOOK2.XLS with the macro
name in the Run method command to run the macro.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Excel for Windows version 5.0c.
To avoid receiving this error message when you use the Run method to
run a macro in a workbook other than the workbook that contains the
current code, do either of the following:
Run "BOOK2.XLS!Macro_Name"
If you are running an auto macro contained on Sheet1, you can call the
macro from another workbook with the following command:
Run "[BOOK2.XLS]Sheet1!Auto_Activate"
NOTE: An Auto_Activate auto macro defined on a worksheet does not
run when the sheet is activated by a Visual Basic procedure.
Run "'" & ActiveWorkbook.Name & "'!Macro_Name"
For more information about the ActiveWorkbook Property, choose the
Search button in the Visual Basic Reference and type:
ActiveWorkbook Property
Run Method
Additional query words: 1.00 demand load err msg
Keywords : xlwin
Version : 5.00
Platform : WINDOWS
Issue type :
Last Reviewed: July 23, 1999