If the condition is true otherwise statements under elseĮach Else block if again have a conditional statementīased on which the statements will be executed. Set of statements under If block are executed Private Sub Workbook_Sync(ByVal SyncEventType As Office.Set of statements are executed only if the condition is true. Private Sub Workbook_SheetTableUpdate(ByVal Sh As Object, ByVal Target As TableObject) Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable) Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable) Private Sub Workbook_SheetPivotTableBeforeDiscardChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long) Private Sub Workbook_SheetPivotTableBeforeCommitChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean) Private Sub Workbook_SheetPivotTableBeforeAllocateChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean) Private Sub Workbook_SheetPivotTableAfterValueChange(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink) Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Private Sub Workbook_SheetCalculate(ByVal Sh As Object) Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) Private Sub Workbook_SheetBeforeDelete(ByVal Sh As Object) Private Sub Workbook_SheetActivate(ByVal Sh As Object) Private Sub Workbook_RowsetComplete(ByVal Description As String, ByVal Sheet As String, ByVal Success As Boolean) Private Sub Workbook_PivotTableOpenConnection(ByVal Target As PivotTable) Private Sub Workbook_PivotTableCloseConnection(ByVal Target As PivotTable) Private Sub Workbook_NewSheet(ByVal Sh As Object) Private Sub Workbook_NewChart(ByVal Ch As Chart) Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Private Sub Workbook_BeforeRemoteChange() Private Sub Workbook_BeforePrint(Cancel As Boolean) Private Sub Workbook_BeforeClose(Cancel As Boolean) Private Sub Workbook_AfterSave(ByVal Success As Boolean) For each event, be sure to copy from "Private Sub." to "End Sub", inclusive.
This article describes the Microsoft Excel "workbook" events - Workbook Events.Ĭopy the appropriate event code from the samples below and paste it to your VBA project. You can go to MSDN and find the syntax for the event you wish to use and type the code manually into your VBA project.
You can perform the similar step on a computer running Excel for Windows and then copy the code to Excel for Mac. Instead, an error occurs that the code is not created.Ĭhoose one of these workarounds for this issue: You can make additional selections from the drop-down list on the right to create additional code to handle the chosen event. If you click the drop-down on the left and choose an item from the list, you should get some code for the selected event in the drop-down list on the right. With this new VB editor, there's an issue with creating object declarations by choosing from the drop-down menu at the top of the code window. In Excel for Mac, a new Visual Basic Editor was introduced in October 2017.