RunAutoMacros Method
Applies To
Workbook object.
Description
Runs the Auto_Open, Auto_Close, Auto_Activate, or Auto_Deactivate macro attached to the workbook. This method is included for backward compatibility. For new Visual Basic code, you should use the Open, Close, Activate and Deactivate events instead of these macros.
Syntax
expression.RunAutoMacros(Which)
expression Required. An expression that returns a Workbook object.
Which Required. The macros to run. Can be one of the following XlRunAutoMacro constants:
Constant | Description |
|
xlAutoOpen | Auto_Open macros |
xlAutoClose | Auto_Close macros |
xlAutoActivate | Auto_Activate macros |
xlAutoDeactivate | Auto_Deactivate macros |
See Also
Activate event, Deactivate event.
Example
This example opens the workbook Analysis.xls and then runs its Auto_Open macro.
Workbooks.Open "Analysis.xls"
ActiveWorkbook.RunAutoMacros xlAutoOpen
This example runs the Auto_Close macro for the active workbook and then closes the workbook.
With ActiveWorkbook
.RunAutoMacros xlAutoClose
.Close
End With