RunAutoMacros Method

Applies To

Workbook Object.

Description

Runs the Auto_Open, Auto_Close, Auto_Activate, or Auto_Deactivate macros that are attached to the workbook.

These four auto macros do not run when workbooks are opened or closed (and when sheets are activated or deactivated) by a Visual Basic program. Use this method to run auto macros.

Syntax

object.RunAutoMacros(which)

object

Required. The Workbook object.

which

Required. Specifies which macros to run, as shown in the following table.

Value

Meaning

xlAutoOpen

Auto_Open macros.

xlAutoClose

Auto_Close macros.

xlAutoActivate

Auto_Activate macros.

xlAutoDeactivate

Auto_Deactivate macros.


Remarks

The Auto_Activate and Auto_Deactivate macros are included for backward compatibility with the Microsoft Excel 4.0 macro language. Use the OnSheetActivate and OnSheetDeactivate properties when you program in Visual Basic.

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