长期潜伏者,第一次海报。这个错误已经困扰了我好几个星期,所以我不得不求助于寻求帮助。
我有一个我开发的excel插件。该插件有一个自定义右键菜单,它取代了标准的 Excel 右键菜单 uning SheetBeforeRightClick。这工作得很好,当您删除您右键单击的行时除外。
例如。您右键单击“主要项目”表上的单元格 E11 以显示菜单。菜单代码:
Private Sub SheetBeforeRightClick(ByVal sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim ClstrCmd As CommandBar
'Display cluster display option commands
On Error GoTo connerr
If ActiveSheet.Name = "Control" Then
Cancel = True
Set ClstrCmd = FinanceCreateSubMenuControlNew
ClstrCmd.ShowPopup
ElseIf ActiveSheet.Name = "Input" Then
Cancel = True
Set ClstrCmd = FinanceCreateSubMenuInputNew
ClstrCmd.ShowPopup
ElseIf ActiveSheet.Name = "Major Projects" Or ActiveSheet.Name = "Projects GP Report" Then
Cancel = True
Set ClstrCmd = FinanceCreateSubMenuProjectsNew
ClstrCmd.ShowPopup
Else
'No Menu for this sheet
End If
connerr:
End Sub
Function FinanceCreateSubMenuProjectsNew() As CommandBar
''Create some objects
Dim cb As CommandBar
Dim cbc As CommandBarControl
''Ensure our popup menu does not exist
FinanceDeleteCommandBar "FINANCE_PROJECTS"
''Add our popup menu to the CommandBars collection
Set cb = CommandBars.Add(Name:="FINANCE_PROJECTS", Position:=msoBarPopup, MenuBar:=False, Temporary:=False)
Set cbc = cb.Controls.Add
With cbc
.Caption = "Insert Seperator Row"
.OnAction = "InsertMajorProjectsSeperator"
End With
Set cbc = cb.Controls.Add
With cbc
.Caption = "Delete Seperator Row"
.OnAction = "DeleteMajorProjectsSeperator"
End With
Set FinanceCreateSubMenuProjectsNew = cb
End Function
您从我的自定义菜单中选择“删除行”。这调用过程删除行。
Sub DeleteRow()
Deleterow = ActiveCell.Row
If ActiveWorkbook.Worksheets("Major Projects").Range("A" & Deleterow) = "x" Then
ActiveWorkbook.Worksheets("Major Projects").Rows(Deleterow).EntireRow.Delete
Else
MsgBox "You haven't selected a seperator to delete"
End If
End Sub
这将删除选定的行。删除该行后,代码将返回 FinanceCreateSubMenuProjectsNew 函数。然后到SheetBeforeRightClick 程序完成。它在 SheetBeforeRightClick 过程中到达 End Sub 并给出 424 - Object requred 错误。没有调试选项,我不能错误捕获它,因为它在 End Sub 之后出现错误。我只能假设它是因为您右键单击的单元格已被删除并且系统丢失了目标。如果我输入一个 msgbox Target.address 我可以导致错误发生在该行。如果我在修复该错误的 msgbox 之前设置 Target = activecell,但它仍然在 End Sub 上出错。我需要重置系统目标类型的变量吗?
即使放入工作表("Major Projects").Range("a1").select 也无济于事。
由于代码错误,插件卸载。因此,用户需要重新启动插件才能再次使用任何功能。
真正的关键是,一旦我重新启动插件,我就可以删除行而不会出现错误。再次出现错误的唯一方法是完全关闭 Excel 并重新开始。仅关闭文件不会导致错误再次发生。