删除命令栏> 1次出现

问题描述 投票:0回答:1

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

我不想像更新等一样编辑其代码,因此每次都需要更改。

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

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
excel vba excel-addins
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.