上次更新时间:2019 年 4 月 10 日
问题
2017 年 10 月,Excel for Mac 中引入了新的 Visual Basic 编辑器。 引入此新 VB 编辑器以来,通过从代码窗口顶部的下拉菜单中进行选择的方式来创建对象声明存在问题。
如果你单击左侧的下拉菜单并从列表中选择一项,应在右侧的下拉列表中获得所选事件的一些代码。 你可以从右侧的下拉列表中进行其他选择,以创建其他代码来处理所选事件。
从而避免发生无法创建代码的错误。
状态:解决方法
请选择以下临时解决方法之一解决此问题:
临时解决方法 1
你可以在运行 Excel for Windows 的计算机上执行相似的步骤,然后将代码复制到 Excel for Mac。
临时解决方法 2
你可以转到 MSDN,找到想要使用的事件的语法,并手动将代码键入 VBA 项目。 本文介绍 Microsoft Excel“工作簿”事件 - 工作簿事件。
临时解决方法 3
复制以下示例中的相应事件代码,并将其粘贴到 VBA 项目。 每个事件都必须从“Private Sub...”部分复制到“End Sub”部分(包含这两句)。
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