XL5: "Cannot Find Macro" Running Macro in Active Workbook

ID: Q115905


The information in this article applies to:


SYMPTOMS

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'.


CAUSE

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.


STATUS

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.


WORKAROUND

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:

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.


REFERENCES

For more information about the ActiveWorkbook Property, choose the Search button in the Visual Basic Reference and type:

ActiveWorkbook Property


For more information about the Run Method, choose the Search button in the Visual Basic Reference and type:

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