对象不会源Office.CommandBarButton对象上的自动化事件(Excel for Mac 2016)

我正在使用本文中描述的代码尝试捕获粘贴事件,并强制它们粘贴特殊以保留我的validation。 作为代码的一部分,有一个类模块:

'------------------------------------------------------------------------- ' Module : clsCommandBarCatch ' Company : JKP Application Development Services (c) ' Author : Jan Karel Pieterse ' Created : 4-10-2007 ' Purpose : This class catches clicks on Excel's commandbars to be able to prevent pasting. '------------------------------------------------------------------------- Option Explicit Public WithEvents oComBarCtl As Office.CommandBarButton '<- Error highlights this line Private Sub Class_Terminate() Set oComBarCtl = Nothing End Sub Private Sub oComBarCtl_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) CancelDefault = True Application.OnTime Now, "MyPasteValues" End Sub 

但是,我不能让代码运行,因为我不断收到编译错误

对象不会产生自动化事件

突出显示上面的行。

我已经检查了我的引用,在我的VBA编辑器的“添加引用”窗口中(我在Excel 2016 for Mac 2016 btw上),并且find了以下库:

  • Visual Basic for Applications
  • Microsoft Excel 14.0对象
  • Microsoft Office 14.0对象
  • Microsoft Forms 2.0对象

以防万一,我也检查了“OLE自动化”。 还有一些其他的库没有检查(“VBAProject”,“EBApp对象库”,其他Office应用程序的库),似乎并不适用于此,所以我没有选中它们。

我也testing了这个Excel的Mac 2011年,并得到了同样的错误。 是否有可能新版本的Excel不使用function区的CommandBar对象b / c?

任何想法如何清除这个错误,赞赏。