Workbook.RunAutoMacros Method (Excel)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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.

expression .RunAutoMacros(Which)

expression A variable that represents a Workbook object.

Parameters

Name

Required/Optional

Data Type

Description

Which

Required

XlRunAutoMacro

Specifies the automatic macro to run.

XlRunAutoMacro can be one of these XlRunAutoMacro constants.

xlAutoActivate. Auto_Activate macros

xlAutoClose. Auto_Close macros

xlAutoDeactivate. Auto_Deactivate macros

xlAutoOpen. Auto_Open macros

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
Show: