这个宏不是我写的,所以我无法理解错误的来源。我有一个宏应该在启动时运行以调整功能区以添加按钮,而另一部分则在您选择该按钮时删除样式。目前,我收到了消息:Object variable or With block variable not set
。当我选择" Debug"它进入VBA屏幕并立即给我3个错误弹出窗口,上面写着: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
我从来没有写过任何激活或功能区相关的宏,所以我不知道错误在哪里。无论这个消息是什么,插件都可以找到,因为按钮被添加并且当文件不是空白文件时它的功能应该是这样,但我弹出错误并且按钮没有被创建对新的空白文件。我怎么能解决这个问题?
答案 0 :(得分:1)
我只是删除了:
Spinner sp;
sp = (Spinner)findViewById(R.id.spUOM);
sp.setAdapter(dataAdapter);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
启动excel时没有运行时错误,使用脚本时没有问题;很好,删除很好。 Windows 7,Excel 2010。