删除命令栏>出现1次

时间:2019-10-24 09:24:10

标签: excel vba excel-addins

我有一个第三方加载项。我的问题是,它计算上次加载的命令栏,如果没有,则重新加载它。

我不想像更新等一样编辑他们的代码,每次都需要更改。

有没有一种方法可以删除除一个命令条以外的所有命令条或更改加载顺序以避免此问题?

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

1 个答案:

答案 0 :(得分:0)


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