Application Level

There are 57 different events.
More details on how to add these events can be found here: VBA > Events > Application Level

EventDescription3652116131007
AfterCalculateOccurs when all synchronous and asynchronous refresh activity and all calculation processes have completed.YYYYYY
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.YYYYYY
ProtectedViewWindowActivateOccurs when a protected view is activated.YYYYY 
ProtectedViewWindowBeforeCloseOccurs before a protected view window or workbook closes.YYYYY 
ProtectedViewWindowBeforeEditOccurs before editing is enabled on the workbook or window.YYYYY 
ProtectedViewWindowDeactivateOccurs when a protected view is deactivated.YYYYY 
ProtectedViewWindowOpenOccurs when a workbook is opened in a protected view window.YYYYY 
ProtectedViewWindowResizeOccurs when any protected view window is resized.YYYYY 
SheetActivateOccurs 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.
YYYYYY
SheetBeforeDeleteOccurs before any sheet is deleted.YYYY  
SheetBeforeDoubleClickOccurs 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).
YYYYYY
SheetBeforeRightClickOccurs 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).
YYYYYY
SheetCalculateOccurs 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).
YYYYYY
SheetChangeOccurs 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).
YYYYYY
SheetDeactivateOccurs 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).
YYYYYY
SheetFollowHyperlinkOccurs when you click any hyperlink in a workbook.YYYYYY
SheetLensGalleryRenderCompleteOccurs after a callout gallery's icons have finished rendering (dynamic and static).YYYY  
SheetPivotTableAfterValueChangeOccurs after a cell or range of cells inside a pivot table are edited or recalculated (for cells that contain formulas).YYYYY 
SheetPivotTableBeforeAllocateChangesOccurs before changes are applied to a pivot table.YYYYY 
SheetPivotTableBeforeCommitChangesOccurs before changes are committed against the OLAP data source for a pivot table.YYYYY 
SheetPivotTableBeforeDiscardChangesOccurs before changes to a pivot table are discarded.YYYYY 
SheetPivotTableUpdateOccurs after the sheet of a pivot table report has been updated.YYYYYY
SheetSelectionChangeOccurs 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.
YYYYYY
SheetTableUpdateOccurs when a table on a worksheet is updated.YYYY  
WindowActivateOccurs when the user moves focus to another window in any open workbook. This should be used instead of the OnWindow property.YYYYYY
WindowDeactivateOccurs when the user moves focus away from an open window in any open workbook. This should be used instead of the OnWindow property.YYYYYY
WindowResizeOccurs 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.
YYYYYY
WorkbookActivateOccurs when the user moves focus to another open workbook.YYYYYY
WorkbookAddinInstallOccurs when the user installs a workbook as an add-in.YYYYYY
WorkbookAddinUninstallOccurs when the user uninstalls a workbook as an add-in.YYYYYY
WorkbookAfterRemoteChangeOccurs after a remote user's edits to the workbook are merged.YY    
WorkbookAfterSaveOccurs after the workbook is saved.YYYY  
WorkbookAfterXmlExportOccurs after Excel saves or exports data from a workbook to an XML data file.YYYYYY
WorkbookAfterXmlImportOccurs after an existing XML data connection is refreshed or after new XML data is imported into the workbook.YYYYYY
WorkbookBeforeCloseOccurs 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.
YYYYYY
WorkbookBeforePrintOccurs before any open workbook is printed.YYYYYY
WorkbookBeforeRemoteChangeOccurs before a remote user's edits to the workbook are merged.YY    
WorkbookBeforeSaveOccurs before any open workbook is saved.YYYYYY
WorkbookBeforeXmlExportOccurs before Excel saves or exports data from a workbook to an XML data file.YYYYYY
WorkbookBeforeXmlImportOccurs before an existing XML data connection is refreshed or after new XML data is imported into the workbook.YYYYYY
WorkbookDeactivateOccurs when the user moves the focus away from any open workbook.YYYYYY
WorkbookModelChangeOccurs when the data model is updated.YYYY  
WorkbookNewChartOccurs when a new chart is created in any open workbook.YYYYY 
WorkbookNewSheetOccurs when the user adds a new worksheet to any open workbook.YYYYYY
WorkbookOpenOccurs when the user opens any workbook.
This event is raised when a new workbook is created from a template or an existing workbook.
YYYYYY
WorkbookPivotTableCloseConnectionOccurs when a pivot table closes its connection to its database.YYYYYY
WorkbookPivotTableOpenConnectionOccurs when a pivot table opens its connection to its database.YYYYYY
WorkbookRowsetCompleteOccurs when a user drills through a recordset or invokes the rowset action on a pivot table object.YYYYYY
WorkbookSyncRedundant. Occurs when a workbook that is part of a document workspace is synchronized with a copy on the server.YYYYYY

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