How do i remove button from "Add-Ins"

I have on "add-Ins" menu button "My button" (see printscreen)
i would like to remove it from there

what should i have to change it the below code to remove it?


Public Sub Workbook_Open()

MacroName1 = "ThisWorkbook.RunComparingInventory"

    Set cbarMenu = Application.CommandBars

    ' First, look for button on the toolbar already.
    For Each cctlControl In cbarMenu("Standard").Controls
        With cctlControl
        If .Caption = "my button" Then
        End If
        If .Caption = "RunComparingInventory" Then
        End If
        End With
    Next cctlControl

    Set cctlControl1 = Application.CommandBars("Standard").Controls.Add(Type:=msoControlButton, Before:=1)
    With cctlControl1
        .Style = msoButtonCaption
        .Caption = "RunComparingInventory"
        .OnAction = MacroName1
        .TooltipText = "Run Comparing Inventory"
        .Enabled = True
    End With
End Sub

Open in new window

Who is Participating?
I'm not sure how you created "my button" so unsure as to what level its at in the commandbar menu structure.

If its at the top level, then you should be searching Application.CommandBars for "my button" then delete.

If its subordinate to "Standard" as you have coded, that should work.

Here's a test code routine that enumerates all command bars, searching for "Standard", then enumerates through controls of "Standard" to find "my button"...

If this doesn't work, then your "my button" control may not be subordinate to "Standard".

Take a look.  

you could provide me the code you use to create the "my button" control then I could zoom in on the problem, more readily...

See the code:
Sub test()
Dim myCmdBar As CommandBar, myControl As CommandBarControl

    For Each myCmdBar In Application.CommandBars
        If myCmdBar.Name = "Standard" Then
            For Each myControl In myCmdBar
                If myControl = "my button" Then
                End If
            Next myControl
        End If
    Next myCmdBar

End Sub

Open in new window


philip m o'brienCommented:
I suggest that you run the following code, then in the list created look for "my button" and check that the caption name is what you think i.e. ensure it has no leading/trailing spaces etc.
If you find it is different then the code provided by Dave will work once amended for the actual caption.
Sub cbarIndex()
Dim cbar As Office.CommandBar
Dim cbc As CommandBarControl, cbtn As CommandBarButton
Dim r As Integer
Dim c As Integer
r = 3
c = 3
Application.ScreenUpdating = False
On Error Resume Next
For Each cbar In Application.CommandBars
Cells(r, c) = cbar.Name
Cells(r, c + 1) = cbar.Type 'msoBarTypeMenuBar,msoBarTypePopup, msoBarTypePopup
r = r + 1
For Each cbc In cbar.Controls
Cells(r, c + 1) = cbc.Caption
Cells(r, c + 2) = cbc.ID
Cells(r, c + 3) = cbc.BuiltIn
Cells(r, c + 4) = cbc.OnAction
If cbc.Type = msoControlButton And Not cbc.BuiltIn Then
Set cbtn = cbc
Selection.Top = Cells(r, c + 5).Top
Selection.Left = Cells(r, c + 5).Left
End If
r = r + 1
r = r + 1
Application.ScreenUpdating = True
End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.