Microsoft KB Archive/46350

{|
 * width="100%"|

Auto_Close, Auto_Open Macros Not Executed in Excel

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0, 5.0c
 * Microsoft Excel for Windows, version 7.0

-

SUMMARY
An Auto_Open macro is a macro that is defined to automatically run when the sheet is opened.

An Auto_Close macro is a macro that is defined to automatically run when the sheet is closed.

These procedures work correctly when you open or close the sheet manually. However, if the sheet is opened or closed by another macro, the automatic macros will not be executed. This behavior is by design.

This is also true for Solver, Q+E, and all add-in macros included in the Microsoft Excel LIBRARY subdirectory. Because the Auto_Open macro does not run when you open these files from another macro sheet, you will be unable to execute any of the menu commands that these add-in macros supply.

Workaround
You can cause the Auto_Open macro to run by simply placing a RUN statement in the calling macro that then runs the Auto_Open macro. An example using the add-in FLATFILE.XLA macro is shown below:

  A2:=OPEN(&quot;Flatfile.xla&quot;) A3:=RUN(Flatfile.xla!Auto_Open)

After executing the RUN statement, you are then able to run any menu commands that FLATFILE.XLA normally supplies.