Share via


Using Events with Microsoft Excel Objects

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

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 sheet, and workbook event procedures are available for any open sheet or workbook. To write event procedures for an embedded chart, query table, or Application object, you must create a new object 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.

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