Workbook Level

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

EventDescription
Activate (VBA)
Cast (WorkbookEvents_Event)
Redundant. Occurs when the focus is moved to this workbook.
AddinInstallOccurs when the workbook is installed as an addin.
This event is only fired when an add-in is manually added to the "Add-ins" dialog box and not when Excel opens. This should be used instead of the Auto_Add macro.
AddinUninstallOccurs when the workbook is uninstalled as an addin.
This event is only fired when an add-in is manually removed from the "Add-ins" dialog box and not when Excel is closed. This should be used instead of the Auto_Remove macro.
AfterRemoteChangeOccurs after a remote user's edits to the workbook are merged.
AfterSaveOccurs when the workbook is saved.
AfterXMLExportOccurs after data is exported to an XML data file.
AfterXMLImportOccurs after data has been imported from an XML data file.
BeforeCloseOccurs before the workbook is closed. This should be used instead of the Auto_Close macro.
BeforePrintOccurs before the workbook is printed.
BeforeRemoteChangeOccurs before a remote user's edits to the workbook are merged.
BeforeSaveOccurs before the workbook is saved. This should be used instead of the OnSave property.
BeforeXMLExportOccurs before data is exported to an XML list.
BeforeXMLImportOccurs before data is imported from an XML list.
DeactivateOccurs when focus is moved from this workbook to another workbook or window.
ModelChangeOccurs when the data model is updated.
NewChartOccurs when a new chart is created in the workbook.
NewSheetOccurs before an additional worksheet is added to the workbook.
OpenOccurs before the workbook is opened. This should be used instead of the Auto_Open macro.
PivotTableCloseConnectionOccurs when a pivot table closes its connection to its datasource.
PivotTableOpenConnectionOccurs when a pivot table opens its connection to its datasource.
RowsetCompleteOccurs when a user either drills through a recordset or involves the rowset action on an OLAP pivot table.
SheetActivateOccurs when any worksheet in this workbook is selected. This should be used instead of the OnSheetActivate property.
The activated sheet is passed an object which can be cast to either a worksheet or a chart sheet
SheetBeforeDeleteOccurs when any sheet is deleted.
SheetBeforeDoubleClickOccurs before any cell is double clicked on any worksheet in this workbook. This should be used instead of the OnDoubleClick property.
SheetBeforeRightClickOccurs before any cell is right mouse clicked on any worksheet in this workbook. This does not include Chart sheets.
SheetCalculateOccurs after the user re-calculates any worksheet in this workbook. This should be used instead of the OnCalculate property.
The activated sheet is passed an object which can be cast to either a worksheet or a chart sheet
SheetChangeOccurs when any cell is changed either by the user or by an external link. This should be used instead of the OnEntry property.
The activated sheet is passed an object although this is always a worksheet as this event is not raised for chart sheets
SheetDeactivateOccurs when a different worksheet is selected in this workbook. This should be used instead of the OnSheetDeactivate property.
The activated sheet is passed an object although this is always a worksheet as this event is not raised for chart sheets
SheetFollowHyperlinkOccurs when a hyperlink is clicked on a worksheet.
SheetLensGalleryRenderCompleteOccurs when a callout gallery's icons (dynamic & static) have completed rendering for a worksheet.
SheetPivotTableAfterValueChangeOccurs after a cell or range of cells inside a pivot table are edited or recalculated (for cells that contain formulas)
SheetPivotTableBeforeAllocateChangeOccurs before changes are applied to a pivot table.
SheetPivotTableBeforeCommitChangesOccurs before changes are committed against the OLAP data source for a pivot table.
SheetPivotTableBeforeDiscardChangesOccurs before changes to a pivot table are discarded.
SheetPivotTableChangeSyncOccurs after changes to a pivot table.
SheetPivotTableUpdateOccurs when a pivot table on a worksheet is updated.
SheetSelectionChangeOccurs when the selection is changed on any worksheets in this workbook. This does not include Chart sheets. The activated sheet is passed an object although this is always a worksheet as this event is not raised for chart sheets.
SheetTableUpdateOccurs after the sheet table has been updated.
SyncRedundant. Occurs when a worksheet in a Document Workspace is synchronised with a copy of the worksheet on a server.
WindowActivateOccurs when focus is moved to any window that displays this workbook. This should be used instead of the OnWindow property.
WindowDeactivateOccurs when any window is de-selected. This should be used instead of the OnWindow property.
WindowResizeOccurs when any window that displays this workbook is resized, opened, maximised or minimised.

Workbook_Activate

Private Sub Workbook_Activate() 
End Sub
private void WbkEvents_WorkbookActivate()
{
    if (mbFireEvents == true)
        WbkEventsActivate_Event?.Invoke();
}
Private Sub WbkEvents_WorkbookActivate() Handles WbkEvents2.Activate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsActivate_Event()
   End If
End Sub

Workbook_AddinInstall

Private Sub Workbook_AddinInstall() 
End Sub
private void WbkEvents_AddinInstall()
{
    if (mbFireEvents == true)
        WbkEventsAddinInstall_Event?.Invoke();
}
Private Sub WbkEvents_AddinInstall() Handles WbkEvents.AddinInstall

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsAddinInstall_Event()
   End If
End Sub

Workbook_AddinUninstall

Private Sub Workbook_AddinUninstall() 
End Sub
private void WbkEvents_AddinUninstall()
{
    if (mbFireEvents == true)
        WbkEventsAddinUninstall_Event?.Invoke();
}
Private Sub WbkEvents_AddinUninstall() Handles WbkEvents.AddinUninstall

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsAddinUninstall_Event()
   End If
End Sub

Workbook_AfterRemoteChange

Private Sub Workbook_AfterRemoteChange() 
End Sub

Workbook_AfterSave

Private Sub Workbook_AfterSave( _ 
   ByVal Success As Boolean)
End Sub

Workbook_AfterXmlExport

Private Sub Workbook_AfterXmlExport( _ 
   ByVal Map As XmlMap, _
   ByVal Url As String, _
   ByVal Result As XlXmlExportResult)
End Sub

Workbook_AfterXmlImport

Private Sub Workbook_AfterXmlImport(ByVal Map As XmlMap, _ 
               ByVal bIsRefresh As Boolean, _
               ByVal Result As xlXmlImportResult)
Dim rgeCell As Range
Dim objWsh As Worksheet
Dim rgeRange As Range

Set objWsh = ThisWorkbook.Worksheets("Sheet1")
Set objRange = objWsh.ListObjects("List1").ListColumns("name").Range

For Each rgeCell In objRange
   If Not (rgeCell.Comment Is Nothing) Then
       objCell.Comment.Delete
   End If

   objCell.AddComment rgeCell.Offset(0,1).Text
Next
End Sub

Workbook_BeforeClose

Private Sub Workbook_BeforeClose( _ 
   ByRef Cancel As Boolean)
End Sub

Workbook_BeforeClose

Private Sub Workbook_BeforePrint( _ 
   ByRef Cancel As Boolean)
End Sub
private void WbkEvents_BeforeClose(ref bool Cancel)
{
    if (mbFireEvents == true)
        WbkEventsBeforeClose_Event?.Invoke(Cancel);
}
Private Sub WbkEvents_BeforeClose(ByRef Cancel As Boolean) _
                                  Handles WbkEvents.BeforeClose

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsBeforeClose_Event(Cancel)
   End If
End Sub

Workbook_BeforePrint

private void WbkEvents_BeforePrint(ref bool Cancel) 
{
    if (mbFireEvents == true)
        WbkEventsBeforePrint_Event?.Invoke(Cancel);
}
Private Sub WbkEvents_BeforePrint(ByRef Cancel As Boolean) _
                                  Handles WbkEvents.BeforePrint

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsBeforePrint_Event(Cancel)
   End If
End Sub

Workbook_BeforeSave

private void WbkEvents_BeforeSave(bool SaveAsUI, ref bool Cancel) 
{
    if (mbFireEvents == true)
        WbkEventsBeforeSave_Event?.Invoke(SaveAsUI, Cancel);
}
Private Sub WbkEvents_BeforeSave(ByVal SaveAsUI As Boolean, _
                                 ByRef Cancel As Boolean) _
                                 Handles WbkEvents.BeforeSave

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsBeforeSave_Event(SaveAsUI, Cancel)
   End If
End Sub

Workbook_BeforeRemoteChange

Private Sub Workbook_BeforeRemoteChange() 
End Sub

Workbook_BeforeSave

Private Sub Workbook_BeforeSave( _ 
   ByVal SaveAsUI As Boolean, _
   ByRef Cancel As Boolean)
End Sub

Workbook_BeforeXmlExport

Private Sub Workbook_BeforeXmlExport( _ 
   ByVal Map As XmlMap, _
   ByVal Url As String, _
   ByRef Cancel As Boolean)
End Sub

Workbook_BeforeXmlImport

Private Sub Workbook_BeforeXmlImport( _ 
   ByVal Map As XmlMap, _
   ByVal Url As String, _
   ByVal IsRefresh As Boolean, _
   ByRef Cancel As Boolean)
End Sub

Workbook_Deactivate

Private Sub Workbook_Deactivate() 
End Sub
private void WbkEvents_Deactivate()
{
    if (mbFireEvents == true)
        WbkEventsDeactivate_Event?.Invoke();
}
Private Sub WbkEvents_Deactivate() Handles WbkEvents.Deactivate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsDeactivate_Event()
   End If
End Sub

Workbook_ModelChange

Private Sub Workbook_ModelChange( _ 
   ByVal Changes As ModelChanges)
End Sub

Workbook_NewChart

Private Sub Workbook_NewChart( _ 
   ByVal Ch As Chart)
End Sub

Workbook_NewSheet

Private Sub Workbook_NewSheet( _ 
   ByVal Sh As Object)
End Sub
private void WbkEvents_NewSheet(object Sh)
{
    if (mbFireEvents == true)
        WbkEventsNewSheet_Event?.Invoke(Sh);
}
Private Sub WbkEvents_NewSheet(ByVal Sh As Object) _
                               Handles WbkEvents.NewSheet

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsNewSheet_Event(Sh)
   End If
End Sub

Workbook_Open

Private Sub Workbook_Open() 
End Sub
private void WbkEvents_Open()
{
    if (mbFireEvents == true)
        WbkEventsOpen_Event?.Invoke();
}
Private Sub WbkEvents_Open() Handles WbkEvents.Open

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsOpen_Event()
   End If
End Sub

Workbook_PivotTableCloseConnection

Private Sub Workbook_PivotTableCloseConnection( _ 
   ByVal Target As PivotTable)
End Sub
private void WbkEvents_PivotTableCloseConnection(Excel.PivotTable Target)
{
    if (mbFireEvents == true)
        WbkEventsPivotTableCloseConnection_Event?.Invoke(Target);
}
Private Sub WbkEvents_PivotTableCloseConnection(ByVal Target As Excel.PivotTable) _
                                                Handles WbkEvents.PivotTableCloseConnection

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsPivotTableCloseConnection_Event(Target)
   End If
End Sub

Workbook_PivotTableOpenConnection

Private Sub Workbook_PivotTableOpenConnection( _ 
   ByVal Target As PivotTable)
End Sub
private void WbkEvents_PivotTableOpenConnection(Excel.PivotTable Target)
{
    if (mbFireEvents == true)
        WbkEventsPivotTableOpenConnection_Event?.Invoke(Target);
}
Private Sub WbkEvents_PivotTableOpenConnection(ByVal Target As Excel.PivotTable) _
                                               Handles WbkEvents.PivotTableOpenConnection

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsPivotTableOpenConnection_Event(Target)
   End If
End Sub

Workbook_RowsetComplete

Private Sub Workbook_RowsetComplete( _ 
   ByVal Description As String, _
   ByVal Sheet As String, _
   ByVal Success As Boolean)
End Sub

Workbook_SheetActivate

Private Sub Workbook_SheetActivate( _ 
   ByVal Sh As Object)
End Sub
private void WbkEvents_SheetActivate(object Sh)
{
    if (mbFireEvents == true)
        WbkEventsSheetActivate_Event?.Invoke(Sh);
}
Private Sub WbkEvents_SheetActivate(ByVal Sh As Object) _
                                    Handles WbkEvents.SheetActivate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetActivate_Event(Sh)
   End If
End Sub

Workbook_SheetBeforeDelete

Private Sub Workbook_SheetBeforeDelete( _ 
   ByVal Sh As Object)
End Sub

Workbook_SheetBeforeDoubleClick

Private Sub Workbook_SheetBeforeDoubleClick( _ 
   ByVal Sh As Object, _
   ByVal Target As Range, _
   ByRef Cancel As Boolean)
End Sub
private void WbkEvents_SheetBeforeDoubleClick(object Sh, Excel.Range Target, ref bool Cancel)
{
    if (mbFireEvents == true)
        WbkEventsSheetBeforeDoubleClick_Event?.Invoke(Sh, Target, Cancel);
}
Private Sub WbkEvents_SheetBeforeDoubleClick(ByVal Sh As Object, _
                                             ByVal Target As Excel.Range, _
                                             ByRef Cancel As Boolean) _
                                             Handles WbkEvents.SheetBeforeDoubleClick

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetBeforeDoubleClick_Event(Sh, Target, Cancel)
   End If
End Sub

Workbook_SheetBeforeRightClick

Private Sub Workbook_SheetBeforeRightClick( _ 
   ByVal Sh As Object, _
   ByVal Target As Range, _
   ByRef Cancel As Boolean)
End Sub

Workbook_SheetCalculate

Private Sub Workbook_SheetCalculate( _ 
   ByVal Sh As Object)
End Sub
private void WbkEvents_SheetCalculate(object Sh)
{
    if (mbFireEvents == true)
        WbkEventsSheetCalculate_Event?.Invoke(Sh);
}
Private Sub WbkEvents_SheetCalculate(ByVal Sh As Object) _
                                     Handles WbkEvents.SheetCalculate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetCalculate_Event(Sh)
   End If
End Sub

Workbook_SheetChange

Private Sub Workbook_SheetChange( _ 
   ByVal Sh As Object, _
   ByVal Target As Range)
End Sub
private void WbkEvents_SheetChange(object Sh, Excel.Range Target)
{
    if (mbFireEvents == true)
        WbkEventsSheetChange_Event?.Invoke(Sh, Target);
}
Private Sub WbkEvents_SheetChange(ByVal Sh As Object, _
                                  ByVal Target As Excel.Range) _
                                  Handles WbkEvents.SheetChange

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetChange_Event(Sh, Target)
   End If
End Sub

Private Sub Workbook_SheetDeactivate( _
   ByVal Sh As Object)
End Sub

Workbook_SheetFollowHyperlink

Private Sub Workbook_SheetFollowHyperlink( _ 
   ByVal Sh As Object, _
   ByVal Target As Hyperlink)
End Sub
private void WbkEvents_SheetFollowHyperlink(object Sh, Excel.Hyperlink Target)
{
    if (mbFireEvents == true)
        WbkEventsSheetFollowHyperlink_Event?.Invoke(Sh, Target);
}
Private Sub WbkEvents_SheetFollowHyperlink(ByVal Sh As Object, _
                                           ByVal Target As Excel.Hyperlink) _
                                           Handles WbkEvents.SheetFollowHyperlink

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetFollowHyperlink_Event(Sh, Target)
   End If
End Sub

Workbook_SheetLensGalleryRenderComplete

Private Sub Workbook_SheetLensGalleryRenderComplete( _ 
   ByVal Sh As Object)
End Sub

Workbook_SheetPivotTableAfterValueChange

Private Sub Workbook_SheetPivotTableAfterValueChange( _ 
   ByVal Sh As Object, _
   ByVal TargetPivotTable As PivotTable, _
   ByVal TargetRange As Range)
End Sub

Workbook_SheetPivotTableBeforeAllocateChanges

Private Sub Workbook_SheetPivotTableBeforeAllocateChanges( _ 
   ByVal Sh As Object, _
   ByVal TargetPivotTable As PivotTable, _
   ByVal ValueChangeStart As Long, _
   ByVal ValueChangeEnd As Long, _
   ByRef Cancel As Boolean)
End Sub

Workbook_SheetPivotTableBeforeCommitChanges

Private Sub Workbook_SheetPivotTableBeforeCommitChanges( _ 
   ByVal Sh As Object, _
   ByVal TargetPivotTable As PivotTable, _
   ByVal ValueChangeStart As Long, _
   ByVal ValueChangeEnd As Long, _
   ByRef Cancel As Boolean)
End Sub

Workbook_SheetPivotTableBeforeDiscardChanges

Private Sub Workbook_SheetPivotTableBeforeDiscardChanges( _ 
   ByVal Sh As Object, _
   ByVal TargetPivotTable As PivotTable, _
   ByVal ValueChangeStart As Long, _
   ByVal ValueChangeEnd As Long)
End Sub

Workbook_SheetPivotTableChangeSync

Private Sub Workbook_SheetPivotTableChangeSync( _ 
   ByVal Sh As Object, _
   ByVal Target As PivotTable)
End Sub

Workbook_SheetPivotTableUpdate

Private Sub Workbook_SheetPivotTableUpdate( _ 
   ByVal Sh As Object, _
   ByVal Target As PivotTable)
End Sub
private void WbkEvents_SheetPivotTableUpdate(object Sh, Excel.PivotTable Target)
{
    if (mbFireEvents == true)
        WbkEventsSheetPivotTableUpdate_Event?.Invoke(Sh, Target);
}
Private Sub WbkEvents_SheetPivotTableUpdate(ByVal Sh As Object, _
                                            ByVal Target As Excel.PivotTable) _
                                            Handles WbkEvents.SheetPivotTableUpdate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetPivotTableUpdate_Event(Sh, Target)
   End If
End Sub

Workbook_SheetSelectionChange

Private Sub Workbook_SheetSelectionChange( _ 
   ByVal Sh As Object, _
   ByVal Target As Range)
End Sub
private void WbkEvents_SheetSelectionChange(object Sh, Excel.Range Target)
{
    if (mbFireEvents == true)
        WbkEventsSheetSelectionChange_Event?.Invoke(Sh, Target);
}
Private Sub WbkEvents_SheetSelectionChange(ByVal Sh As Object, _
                                           ByVal Target As Excel.Range) _
                                           Handles WbkEvents.SheetSelectionChange

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsSheetSelectionChange_Event(Sh, Target)
   End If
End Sub

Workbook_SheetTableUpdate

Private Sub Workbook_SheetTableUpdate( _ 
   ByVal Sh As Object, _
   ByVal Target As TableObject)
End Sub

Workbook_Sync

Private Sub Workbook_Sync( _ 
   ByVal SyncEventType As Office.MsoSyncEventType)
End Sub

Workbook_WindowActivate

Private Sub Workbook_WindowActivate( _ 
   ByVal Wn As Window)
End Sub
private void WbkEvents_WindowActivate(Excel.Window Wn)
{
    if (mbFireEvents == true)
        WbkEventsWindowActivate_Event?.Invoke(Wn);
}
Private Sub WbkEvents_WindowActivate(ByVal Wn As Excel.Window) Handles _
                                     WbkEvents.WindowActivate

   If (mbFireEvents = True) Then
      RaiseEvent WbkEventsWindowActivate_Event(Wn)
   End If
End Sub

Workbook_WindowDeactivate

Private Sub Workbook_WindowDeactivate( _ 
   ByVal Wn As Window)
End Sub

Workbook_WindowResize

Private Sub Workbook_WindowResize( _ 
   ByVal Wn As Window)
End Sub

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext