Excel VBA – 命令栏 – 更改variables的属性?

在我正在进行的创造这个简单的插件工作的战斗。

我现在决定使用命令栏中的命令button打开和closures提醒,这是我下面的代码。

Private Sub App_WorkbookOpen(ByVal Wb As Workbook) Dim cmbBar As CommandBar Dim cmbControl As CommandBarControl Set cmbBar = Application.CommandBars("Worksheet Menu Bar") Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True) 'adds a menu item to the Menu Bar With cmbControl .Caption = "LLE Encryption Reminder" 'names the menu item With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item .Caption = "Enable Reminder" 'adds a description to the menu item .OnAction = "'Enable'" .FaceId = 343 'assigns an icon to the dropdown End With With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item .Caption = "Disable Reminder" 'adds a description to the menu item .OnAction = "'Disable'" .FaceId = 342 'assigns an icon to the dropdown End With End With End Sub Private Sub Enable() Response = True End Sub Private Sub Disable() Response = False End Sub 

响应是一个布尔值,我试过各种各样的工作,它每次都返回相同的错误“无法运行macros”path名“macros可能无法在此工作簿或所有macros可能被禁用。

你如何克服这个问题?

同样,在同一个话题上,有没有反映我反映的状态的标签?

这个代码是在一个名为CExcelEvents的类模块中,通过阅读本网站的一个新类模块中的应用程序事件http://www.cpearson.com/Excel/AppEvent.aspx后,我觉得我的代码需要进入我的插件同一个class级的模块,我错了吗? 在这个工作簿中,我有以下用于使我的课程模块工作的代码。

 Private XLApp As CExcelEvents Private Sub Workbook_Open() Set XLApp = New CExcelEvents End Sub 

我通过将subs和公共variables移动到一个单独的模块而不是一个类模块来解决这个问题,然后sorting了我​​所遇到的问题。