Applies ToExcel 2016 for Mac

上次更新时间:2019 年 4 月 10 日

问题

2017 年 10 月,Excel for Mac 中引入了新的 Visual Basic 编辑器。 引入此新 VB 编辑器以来,通过从代码窗口顶部的下拉菜单中进行选择的方式来创建对象声明存在问题。

如果你单击左侧的下拉菜单并从列表中选择一项,应在右侧的下拉列表中获得所选事件的一些代码。 你可以从右侧的下拉列表中进行其他选择,以创建其他代码来处理所选事件。

显示对象选择下拉列表的 VB 编辑器

从而避免发生无法创建代码的错误。

Microsoft Visual Basic 错误:变量使用 Visual Basic.中不支持的 Automation 类型。

状态:解决方法

请选择以下临时解决方法之一解决此问题:

临时解决方法 1

你可以在运行 Excel for Windows 的计算机上执行相似的步骤,然后将代码复制到 Excel for Mac。

临时解决方法 2

你可以转到 MSDN,找到想要使用的事件的语法,并手动将代码键入 VBA 项目。 本文介绍 Microsoft Excel“工作簿”事件 - 工作簿事件

临时解决方法 3

复制以下示例中的相应事件代码,并将其粘贴到 VBA 项目。 每个事件都必须从“Private Sub...”部分复制到“End Sub”部分(包含这两句)。

Private Sub Workbook_Activate() End Sub

Private Sub Workbook_AddinInstall() End Sub

Private Sub Workbook_AddinUninstall() End Sub

Private Sub Workbook_AfterRemoteChange() End Sub

Private Sub Workbook_AfterSave(ByVal Success As Boolean) End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean) End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean) End Sub

Private Sub Workbook_BeforeRemoteChange() End Sub

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

Private Sub Workbook_Deactivate() End Sub

Private Sub Workbook_NewChart(ByVal Ch As Chart) End Sub

Private Sub Workbook_NewSheet(ByVal Sh As Object) End Sub

Private Sub Workbook_Open() End Sub

Private Sub Workbook_PivotTableCloseConnection(ByVal Target As PivotTable) End Sub

Private Sub Workbook_PivotTableOpenConnection(ByVal Target As PivotTable) End Sub

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

Private Sub Workbook_SheetActivate(ByVal Sh As Object) End Sub

Private Sub Workbook_SheetBeforeDelete(ByVal Sh As Object) End Sub

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) End Sub

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

Private Sub Workbook_SheetCalculate(ByVal Sh As Object) End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) End Sub

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink) End Sub

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

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

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

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

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

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

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) End Sub

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

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

Private Sub Workbook_WindowActivate(ByVal Wn As Window) End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window) End Sub

Private Sub Workbook_WindowResize(ByVal Wn As Window) End Sub

Private 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

更多资源

专家图标(大脑、齿轮)

询问专家

与专家联系,讨论 Excel 最新资讯、更新和最佳做法,并阅读我们的博客。

Excel 技术社区

社区图标

在社区中获取帮助

提出问题,查找来自支持人员、MVP、工程师和其他 Excel 用户的解决方案。

Excel 论坛解答

功能请求图标(灯泡、想法)

推荐新功能

欢迎大家踊跃提出建议和反馈! 分享你的想法。 我们将认真听取你的建议。

提供反馈

另请参阅

Excel for Mac 中最新问题的修复或解决方法

需要更多帮助?

需要更多选项?

了解订阅权益、浏览培训课程、了解如何保护设备等。

社区可帮助你提出和回答问题、提供反馈,并听取经验丰富专家的意见。

查找常见问题的解决方案或从支持代理获取帮助。