Application Level

There are 57 different events.

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


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_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_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

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


© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

PrevNext