删除命令栏 > 1 次
Delete Command Bars > 1 occurence
我有第三方插件。我的问题是,它计算最后加载的命令栏,如果不存在,它会重新加载它。
我不想像更新等那样编辑他们的代码,每次都需要更改。
有没有一种方法可以删除除一个命令栏之外的所有命令栏或更改加载顺序以避免此问题?
Public Sub ABCInitializeAddin()
Dim menuEntries As Integer
Dim lastIndex As Integer
' Get number of menu entries
menuEntries = Application.CommandBars(WorksheetMenuBar).Controls.Count
' Get index of last entry
lastIndex = Application.CommandBars(WorksheetMenuBar).Controls(menuEntries).Index
If Not Application.CommandBars(WorksheetMenuBar).Controls(lastIndex - 1).Caption = ABCMenuEntry Then
' Add main menu entry
Dim ABCMainMenu As CommandBarControl
Set ABCMainMenu = CommandBars(WorksheetMenuBar).Controls.Add(Type:=msoControlPopup, Before:=lastIndex)
ABCMainMenu.Caption = ABCMenuEntry
End Sub
Sub STDeleteXavex()
Dim menuEntries As Integer
Dim lastIndex As Integer
Dim i As Long
Dim p As Long
Dim count As Long
count = -1
' Get number of menu entries
menuEntries = Application.CommandBars("Worksheet Menu Bar").Controls.count
For i = 1 To menuEntries:
If Application.CommandBars("Worksheet Menu Bar").Controls(i).Caption = "&ABC Online" Then count = count + 1
Next i
For p = 1 To count:
Application.CommandBars("Worksheet Menu Bar").Controls("ABC Online").Delete
Next p
End Sub
我有第三方插件。我的问题是,它计算最后加载的命令栏,如果不存在,它会重新加载它。
我不想像更新等那样编辑他们的代码,每次都需要更改。
有没有一种方法可以删除除一个命令栏之外的所有命令栏或更改加载顺序以避免此问题?
Public Sub ABCInitializeAddin()
Dim menuEntries As Integer
Dim lastIndex As Integer
' Get number of menu entries
menuEntries = Application.CommandBars(WorksheetMenuBar).Controls.Count
' Get index of last entry
lastIndex = Application.CommandBars(WorksheetMenuBar).Controls(menuEntries).Index
If Not Application.CommandBars(WorksheetMenuBar).Controls(lastIndex - 1).Caption = ABCMenuEntry Then
' Add main menu entry
Dim ABCMainMenu As CommandBarControl
Set ABCMainMenu = CommandBars(WorksheetMenuBar).Controls.Add(Type:=msoControlPopup, Before:=lastIndex)
ABCMainMenu.Caption = ABCMenuEntry
End Sub
Sub STDeleteXavex()
Dim menuEntries As Integer
Dim lastIndex As Integer
Dim i As Long
Dim p As Long
Dim count As Long
count = -1
' Get number of menu entries
menuEntries = Application.CommandBars("Worksheet Menu Bar").Controls.count
For i = 1 To menuEntries:
If Application.CommandBars("Worksheet Menu Bar").Controls(i).Caption = "&ABC Online" Then count = count + 1
Next i
For p = 1 To count:
Application.CommandBars("Worksheet Menu Bar").Controls("ABC Online").Delete
Next p
End Sub