Application Level
There are 57 different events.
More details on how to add these events can be found here: VBA > Events > Application Level
Event | Description | 365 | 21 | 16 | 13 | 10 | 07 |
AfterCalculate | Occurs when all synchronous and asynchronous refresh activity and all calculation processes have completed. | Y | Y | Y | Y | Y | Y |
NewWorkbook Cast (AppEvents_Event) | Occurs when a new workbook is created. This event is not raised when a new workbook is created from a template or an existing workbook. | Y | Y | Y | Y | Y | Y |
ProtectedViewWindowActivate | Occurs when a protected view is activated. | Y | Y | Y | Y | Y | |
ProtectedViewWindowBeforeClose | Occurs before a protected view window or workbook closes. | Y | Y | Y | Y | Y | |
ProtectedViewWindowBeforeEdit | Occurs before editing is enabled on the workbook or window. | Y | Y | Y | Y | Y | |
ProtectedViewWindowDeactivate | Occurs when a protected view is deactivated. | Y | Y | Y | Y | Y | |
ProtectedViewWindowOpen | Occurs when a workbook is opened in a protected view window. | Y | Y | Y | Y | Y | |
ProtectedViewWindowResize | Occurs when any protected view window is resized. | Y | Y | Y | Y | Y | |
SheetActivate | Occurs when any worksheet (worksheet or chart sheet) in any open workbook is selected. This should be used instead of the OnSheetActivate property. The activated sheet is passed as an object which can be cast either to a worksheet or chart. | Y | Y | Y | Y | Y | Y |
SheetBeforeDelete | Occurs before any sheet is deleted. | Y | Y | Y | Y | ||
SheetBeforeDoubleClick | Occurs before any cell in any worksheet in any workbook is double clicked. This does not include Chart sheets. This should be used instead of the OnDoubleClick property. This occurs before the default double click. The activated sheet is passed as an object although this object can only be a worksheet (never a chart). | Y | Y | Y | Y | Y | Y |
SheetBeforeRightClick | Occurs before the user right clicks on any worksheet in any open workbook. This does not include Chart sheets. The activated sheet is passed as an object although this object can only be a worksheet (never a chart). | Y | Y | Y | Y | Y | Y |
SheetCalculate | Occurs after the user recalculates any worksheet in any workbook. This does not include Chart sheets. This should be used instead of the OnCalculate property. The activated sheet is passed as an object although this object can only be a worksheet (never a chart). | Y | Y | Y | Y | Y | Y |
SheetChange | Occurs when the user changes a cell formula in any worksheet in any open workbook. This does not include Chart sheets. This should be used instead of the OnEntry property. The activated sheet is passed as an object although this object can only be a worksheet (never a chart). | Y | Y | Y | Y | Y | Y |
SheetDeactivate | Occurs when the user deactivates any worksheet in any open workbook. This should be used instead of the OnSheetDeactivate property. The activated sheet is passed as an object although this object can only be a worksheet (never a chart). | Y | Y | Y | Y | Y | Y |
SheetFollowHyperlink | Occurs when you click any hyperlink in a workbook. | Y | Y | Y | Y | Y | Y |
SheetLensGalleryRenderComplete | Occurs after a callout gallery's icons have finished rendering (dynamic and static). | Y | Y | Y | Y | ||
SheetPivotTableAfterValueChange | Occurs after a cell or range of cells inside a pivot table are edited or recalculated (for cells that contain formulas). | Y | Y | Y | Y | Y | |
SheetPivotTableBeforeAllocateChanges | Occurs before changes are applied to a pivot table. | Y | Y | Y | Y | Y | |
SheetPivotTableBeforeCommitChanges | Occurs before changes are committed against the OLAP data source for a pivot table. | Y | Y | Y | Y | Y | |
SheetPivotTableBeforeDiscardChanges | Occurs before changes to a pivot table are discarded. | Y | Y | Y | Y | Y | |
SheetPivotTableUpdate | Occurs after the sheet of a pivot table report has been updated. | Y | Y | Y | Y | Y | Y |
SheetSelectionChange | Occurs when the user changes the current selection on any worksheet in any open workbook. The activated sheet is passed as an object although this object can only be a worksheet. This event is not raised on chart sheets. | Y | Y | Y | Y | Y | Y |
SheetTableUpdate | Occurs when a table on a worksheet is updated. | Y | Y | Y | Y | ||
WindowActivate | Occurs when the user moves focus to another window in any open workbook. This should be used instead of the OnWindow property. | Y | Y | Y | Y | Y | Y |
WindowDeactivate | Occurs when the user moves focus away from an open window in any open workbook. This should be used instead of the OnWindow property. | Y | Y | Y | Y | Y | Y |
WindowResize | Occurs when the user resizes or minimises any window in any open workbook. Only fired if the workbook window is not maximised. Does not fire when you resize or minimise the outer application window. | Y | Y | Y | Y | Y | Y |
WorkbookActivate | Occurs when the user moves focus to another open workbook. | Y | Y | Y | Y | Y | Y |
WorkbookAddinInstall | Occurs when the user installs a workbook as an add-in. | Y | Y | Y | Y | Y | Y |
WorkbookAddinUninstall | Occurs when the user uninstalls a workbook as an add-in. | Y | Y | Y | Y | Y | Y |
WorkbookAfterRemoteChange | Occurs after a remote user's edits to the workbook are merged. | Y | Y | ||||
WorkbookAfterSave | Occurs after the workbook is saved. | Y | Y | Y | Y | ||
WorkbookAfterXmlExport | Occurs after Excel saves or exports data from a workbook to an XML data file. | Y | Y | Y | Y | Y | Y |
WorkbookAfterXmlImport | Occurs after an existing XML data connection is refreshed or after new XML data is imported into the workbook. | Y | Y | Y | Y | Y | Y |
WorkbookBeforeClose | Occurs before any open workbook is closed. This gives you a chance to prevent the closing of a workbook. If the event handler sets the cancel to true, the pending close is cancelled and the workbook remains open. Cannot be used to determine if a workbook is actually going to be closed because this event is fired before the user is prompted to save any changes and they could press Cancel. This event is fired after the Workbook.BeforeClose event. | Y | Y | Y | Y | Y | Y |
WorkbookBeforePrint | Occurs before any open workbook is printed. | Y | Y | Y | Y | Y | Y |
WorkbookBeforeRemoteChange | Occurs before a remote user's edits to the workbook are merged. | Y | Y | ||||
WorkbookBeforeSave | Occurs before any open workbook is saved. | Y | Y | Y | Y | Y | Y |
WorkbookBeforeXmlExport | Occurs before Excel saves or exports data from a workbook to an XML data file. | Y | Y | Y | Y | Y | Y |
WorkbookBeforeXmlImport | Occurs before an existing XML data connection is refreshed or after new XML data is imported into the workbook. | Y | Y | Y | Y | Y | Y |
WorkbookDeactivate | Occurs when the user moves the focus away from any open workbook. | Y | Y | Y | Y | Y | Y |
WorkbookModelChange | Occurs when the data model is updated. | Y | Y | Y | Y | ||
WorkbookNewChart | Occurs when a new chart is created in any open workbook. | Y | Y | Y | Y | Y | |
WorkbookNewSheet | Occurs when the user adds a new worksheet to any open workbook. | Y | Y | Y | Y | Y | Y |
WorkbookOpen | Occurs when the user opens any workbook. This event is raised when a new workbook is created from a template or an existing workbook. | Y | Y | Y | Y | Y | Y |
WorkbookPivotTableCloseConnection | Occurs when a pivot table closes its connection to its database. | Y | Y | Y | Y | Y | Y |
WorkbookPivotTableOpenConnection | Occurs when a pivot table opens its connection to its database. | Y | Y | Y | Y | Y | Y |
WorkbookRowsetComplete | Occurs when a user drills through a recordset or invokes the rowset action on a pivot table object. | Y | Y | Y | Y | Y | Y |
WorkbookSync | Redundant. Occurs when a workbook that is part of a document workspace is synchronized with a copy on the server. | Y | Y | Y | Y | Y | Y |
Activate and Deactivate
Switching focus between applications does not trigger activation or deactivation of any of the Application, Workbook, Worksheet or Windows events.
VBA Samples
Private Sub Application_AfterCalculate()
End Sub
Private Sub Application_NewWorkbook( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_ProtectedViewWindowActivate( _
ByVal Pvw As ProtectedViewWindow)
End Sub
Private Sub Application_ProtectedViewWindowBeforeClose( _
ByVal Pvw As ProtectedViewWindow, _
ByVal Reason As XlProtectedViewCloseReason,
ByRef Cancel As Boolean)
End Sub
Private Sub Application_ProtectedViewWindowBeforeEdit( _
ByVal Pvw As ProtectedViewWindow, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_ProtectedViewWindowDeactivate( _
ByVal Pvw As ProtectedViewWindow)
End Sub
Private Sub Application_ProtectedViewWindowOpen( _
ByVal Pvw As ProtectedViewWindow)
End Sub
Private Sub Application_ProtectedViewWindowResize( _
ByVal Pvw As ProtectedViewWindow)
End Sub
Private Sub Application_SheetActivate( _
ByVal Sh As Object)
End Sub
Private Sub Application_SheetBeforeDelete( _
ByVal Sh As Object)
End Sub
Private Sub Application_SheetBeforeDoubleClick( _
ByVal Sh As Object, _
ByVal Target As Range, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_SheetBeforeRightClick( _
ByVal Sh As Object, _
ByVal Target As Range, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_SheetCalculate( _
ByVal Sh As Object)
End Sub
Private Sub Application_SheetChange( _
ByVal Sh As Object, _
ByVal Target As Range)
End Sub
Private Sub Application_SheetDeactivate( _
ByVal Sh As Object)
End Sub
Private Sub Application_SheetFollowHyperlink( _
ByVal Sh As Object, _
ByVal Target As Hyperlink)
End Sub
Private Sub Application_SheetLensGalleryRenderComplete( _
ByVal Sh As Object)
End Sub
Private Sub Application_SheetPivotTableAfterValueChange( _
ByVal Sh As Object, _
ByVal TargetPivotTable As PivotTable, _
ByVal TargetRange As Range)
End Sub
Private Sub Application_SheetPivotTableBeforeAllocateChanges( _
ByVal Sh As Object, _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_SheetPivotTableBeforeCommitChanges( _
ByVal Sh As Object, _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_SheetPivotTableBeforeDiscardChanges( _
ByVal Sh As Object, _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long)
End Sub
Private Sub Application_SheetPivotTableUpdate( _
ByVal Sh As Object, _
ByVal Target As PivotTable)
End Sub
Private Sub Application_SheetSelectionChange( _
ByVal Sh As Object, _
ByVal Target As Range)
End Sub
Private Sub Application_SheetTableUpdate( _
ByVal Sh As Object, _
ByVal Target As TableObject)
End Sub
Private Sub Application_WindowActivate( _
ByVal Wb As Workbook, _
ByVal Wn As Window)
End Sub
Private Sub Application_WindowDeactivate( _
ByVal Wb As Workbook, _
ByVal Wn As Window)
End Sub
Private Sub Application_WindowResize( _
ByVal Wb As Workbook, _
ByVal Wn As Window)
End Sub
Private Sub Application_WorkbookActivate( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_WorkbookAddinInstall( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_WorkbookAddinUninstall( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_WorkbookAfterRemoteChange()
End Sub
Private Sub Application_WorkbookAfterSave( _
ByVal Wb As Workbook, _
ByVal Success As Boolean)
End Sub
Private Sub Application_WorkbookAfterXmlExport( _
ByVal Wb As Workbook, _
ByVal Map As XmlMap, _
ByVal Url As String, _
ByVal Result As XlXmlExportResult)
End Sub
Private Sub Application_WorkbookAfterXmlImport( _
ByVal Wb As Workbook, _
ByVal Map As XmlMap, _
ByVal IsRefresh As Boolean, _
ByVal Result As XlXmlImportResult)
End Sub
Private Sub Application_WorkbookBeforeClose( _
ByVal Wb As Workbook, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_WorkbookBeforePrint( _
ByVal Wb As Workbook, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_WorkbookBeforeRemoteChange()
End Sub
Private Sub Application_WorkbookBeforeSave( _
ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_WorkbookBeforeXmlExport( _
ByVal Wb As Workbook, _
ByVal Map As XmlMap, _
ByVal Url As String, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_WorkbookBeforeXmlImport( _
ByVal Wb As Workbook, _
ByVal Map As XmlMap, _
ByVal Url As String, _
ByVal IsRefresh As Boolean, _
ByRef Cancel As Boolean)
End Sub
Private Sub Application_WorkbookDeactivate( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_WorkbookModelChange( _
ByVal Wb As Workbook, _
ByVal Changes As ModelChanges)
End Sub
Private Sub Application_WorkbookNewChart( _
ByVal Wb As Workbook, _
ByVal Ch As Chart)
End Sub
Private Sub Application_WorkbookNewSheet( _
ByVal Wb As Workbook, _
ByVal Sh As Object)
End Sub
Private Sub Application_WorkbookOpen( _
ByVal Wb As Workbook)
End Sub
Private Sub Application_WorkbookPivotTableCloseConnection( _
ByVal Wb As Workbook, _
ByVal Target As PivotTable)
End Sub
Private Sub Application_WorkbookPivotTableOpenConnection( _
ByVal Wb As Workbook, _
ByVal Target As PivotTable)
End Sub
Private Sub Application_WorkbookRowsetComplete( _
ByVal Wb As Workbook, _
ByVal Description As String, _
ByVal Sheet As String, _
ByVal Success As Boolean)
End Sub
Private Sub Application_WorkbookSync( _
ByVal Wb As Workbook, _
ByVal SyncEventType As Office.MsoSyncEventType)
End Sub
C# Samples
For examples in C# refer to the [[Excel Interop > Event Handling]] page.
void WhichObject (string eventName, object sheet)
{
Excel.Worksheet wsh = sheet as Excel.Worksheet
if (worksheet != null)
{
// this is a worksheet
}
Excel.Chart cht = sheet as Excel.Chart
{
// this is a chart
}
}
In VSTO you do not have to keep a reference to the workbook, worksheet or chart objects when handling events because they are already being kept by the project items generated by the project.
However you do need to keep a reference to the Application object
To get a worksheet or chart we can use the VSTO's Global object
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext