Using events with Excel objects

You can write event procedures in Microsoft Excel at the worksheet, chart, query table, workbook, or application level. For example, the Activate event occurs at the sheet level, and the SheetActivate event is available at both the workbook and application levels. The SheetActivate event for a workbook occurs when any sheet in the workbook is activated. At the application level, the SheetActivate event occurs when any sheet in any open workbook is activated.

Worksheet, Chart, and event procedures are available for any open sheet or workbook. To write event procedures for an embedded chart, a QueryTable object, or an Application object, you must create a new object by using the WithEvents keyword in a class module.

Use the EnableEvents property to enable or disable events. For example, using the Save method to save a workbook causes the BeforeSave event to occur. You can prevent this by setting the EnableEvents property to False before you call the Save method.

Example

Application.EnableEvents = False 
ActiveWorkbook.Save 
Application.EnableEvents = True

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.