未设置块variables – 工作簿打开时出错

这个macros是不是由我写的,所以我很难理解错误的来源。 我有一个应该在启动时运行的macros来调整function区以添加一个button,另一部分是在select该button时删除样式。 目前,我得到消息: Object variable or With block variable not set 。 当我select“debugging”它进入VBA屏幕,并立即给我3错误popup窗口说: Can't execute code in break mode

第一部分是在启动时运行的两个子目录,它们是:

 Dim WithEvents app As Application Private Sub App_WorkbookActivate(ByVal Wb As Workbook) Module1.MyRibbon.Invalidate End Sub Private Sub Workbook_Open() Set app = Application End Sub 

它突出了Module1.MyRibbon.Invalidate作为有问题的位。 就我个人而言,我本身并没有看到任何问题,但问题可能在模块1中? 该代码包含三个子目录,如下所示:

 Public MyRibbon As IRibbonUI 'Callback for customUI.onLoad Sub CallbackOnLoad(Ribbon As IRibbonUI) Set MyRibbon = Ribbon End Sub 'Callback for customButton getLabel Sub GetButtonLabel(control As IRibbonControl, ByRef returnedVal) If ActiveWorkbook Is Nothing Then returnedVal = "Remove Styles" Else returnedVal = "Remove Styles" & vbCr & Format(ActiveWorkbook.Styles.Count, "#" & Application.International(xlThousandsSeparator) & "##0") End If End Sub Sub RemoveTheStyles(control As IRibbonControl) Dim s As Style, i As Long, c As Long On Error Resume Next If ActiveWorkbook.MultiUserEditing Then If MsgBox("You cannot remove Styles in a Shared workbook." & vbCr & vbCr & _ "Do you want to unshare the workbook?", vbYesNo + vbInformation) = vbYes Then ActiveWorkbook.ExclusiveAccess If Err.Description = "Application-defined or object-defined error" Then Exit Sub End If Else Exit Sub End If End If c = ActiveWorkbook.Styles.Count Application.ScreenUpdating = False For i = c To 1 Step -1 If i Mod 600 = 0 Then DoEvents Set s = ActiveWorkbook.Styles(i) Application.StatusBar = "Deleting " & c - i + 1 & " of " & c & " " & s.Name If Not s.BuiltIn Then s.Delete If Err.Description = "You cannot use this command on a protected sheet. To use this command, you must first unprotect the sheet (Review tab, Changes group, Unprotect Sheet button). You may be prompted for a password." Then MsgBox Err.Description & vbCr & "You have to unprotect all of the sheets in the workbook to remove styles.", vbExclamation, "Remove Styles AddIn" Exit For End If End If Next Application.ScreenUpdating = True Application.StatusBar = False End Sub 

我从来没有写过任何激活或function区相关的macros,所以我不知道错误在哪里。 插件工程只是find不pipe这个消息,因为button被添加,它的function,因为它应该当文件不是一个空白的文件,但我得到的错误popup,并没有得到创build新的权利,在新的,空白文件。 我怎么能解决这个问题?

我简单地删除了:

  Private Sub App_WorkbookActivate(ByVal Wb As Workbook) Module1.MyRibbon.Invalidate End Sub 

Excel的开始没有运行时错误,使用脚本时没有问题; 计数正确,删除罚款。 Windows 7,Excel 2010。