RunAutoMacros Method

Microsoft Excel Visual Basic

expression.RunAutoMacros(Which)

expression    Required. An expression that returns one of the objects in the Applies To list.

Which   Required XlRunAutoMacro.

XlRunAutoMacro can be one of these XlRunAutoMacro constants.
xlAutoActivate. Auto_Activate macros
xlAutoClose. Auto_Close macros
xlAutoDeactivate. Auto_Deactivate macros
xlAutoOpen. Auto_Open macros

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