Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

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?

Thanks
Gvilbis


Public Sub Workbook_Open()

Stop
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
                .Delete
        End If
        
        If .Caption = "RunComparingInventory" Then
                .Delete
        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

my-button.jpg
0
gvilbis
Asked:
gvilbis
2 Solutions
 
dlmilleCommented:
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
                    myControl.Delete
                End If
            Next myControl
        End If
    Next myCmdBar

End Sub

Open in new window

Enjoy!

Dave
0
 
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.
Regards
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
cbtn.CopyFace
ActiveSheet.Paste
Selection.Top = Cells(r, c + 5).Top
Selection.Left = Cells(r, c + 5).Left
End If
r = r + 1
Next
r = r + 1
Next
Application.ScreenUpdating = True
End Sub

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now