Last Updated: April 10, 2019
ISSUE
In Excel for Mac, a new Visual Basic Editor was introduced in October 2017. 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.
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. You can make additional selections from the drop-down list on the right to create additional code to handle the chosen event.
Instead, an error occurs that the code is not created.
STATUS: WORKAROUND
Choose one of these workarounds for this issue:
WORKAROUND #1
You can perform the similar step on a computer running Excel for Windows and then copy the code to Excel for Mac.
WORKAROUND #2
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. This article describes the Microsoft Excel "workbook" events - Workbook Events.
WORKAROUND #3
Copy the appropriate event code from the samples below and paste it to your VBA project. For each event, be sure to copy from "Private Sub..." to "End Sub", inclusive.
Private Sub Workbook_Activate()
End SubPrivate Sub Workbook_AddinInstall()
End SubPrivate Sub Workbook_AddinUninstall()
End SubPrivate Sub Workbook_AfterRemoteChange()
End SubPrivate Sub Workbook_AfterSave(ByVal Success As Boolean)
End SubPrivate Sub Workbook_BeforeClose(Cancel As Boolean)
End SubPrivate Sub Workbook_BeforePrint(Cancel As Boolean)
End SubPrivate Sub Workbook_BeforeRemoteChange()
End SubPrivate Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
End SubPrivate Sub Workbook_Deactivate()
End SubPrivate Sub Workbook_NewChart(ByVal Ch As Chart)
End SubPrivate Sub Workbook_NewSheet(ByVal Sh As Object)
End SubPrivate Sub Workbook_Open()
End SubPrivate Sub Workbook_PivotTableCloseConnection(ByVal Target As PivotTable)
End SubPrivate Sub Workbook_PivotTableOpenConnection(ByVal Target As PivotTable)
End SubPrivate Sub Workbook_RowsetComplete(ByVal Description As String, ByVal Sheet As String, ByVal Success As Boolean)
End SubPrivate Sub Workbook_SheetActivate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetBeforeDelete(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetCalculate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
End SubPrivate Sub Workbook_SheetDeactivate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
End SubPrivate Sub Workbook_SheetPivotTableAfterValueChange(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
End SubPrivate Sub Workbook_SheetPivotTableBeforeAllocateChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetPivotTableBeforeCommitChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetPivotTableBeforeDiscardChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long)
End SubPrivate Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable)
End SubPrivate Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
End SubPrivate Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
End SubPrivate Sub Workbook_SheetTableUpdate(ByVal Sh As Object, ByVal Target As TableObject)
End SubPrivate Sub Workbook_Sync(ByVal SyncEventType As Office.MsoSyncEventType)
End SubPrivate Sub Workbook_WindowActivate(ByVal Wn As Window)
End SubPrivate Sub Workbook_WindowDeactivate(ByVal Wn As Window)
End SubPrivate Sub Workbook_WindowResize(ByVal Wn As Window)
End SubPrivate Sub Worksheet_Activate()
End Sub
Private Sub Worksheet_BeforeDelete()
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_Calculate()
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
Private Sub Worksheet_Deactivate()
End Sub
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
End Sub
Private Sub Worksheet_LensGalleryRenderComplete()
End Sub
Private Sub Worksheet_PivotTableAfterValueChange(ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
End Sub
Private Sub Worksheet_PivotTableBeforeAllocateChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeCommitChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeDiscardChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long)
End Sub
Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
End Sub
More Resources
Ask the experts
Connect with experts, discuss the latest Excel news, updates, and best practices, and read our blog.
Get help in the community
Ask a question and find solutions from Support Agents, MVPs, Engineers, and other Excel users.
Suggest a new feature
We love reading your suggestions and feedback! Share your thoughts. We're listening.