Worksheet Menu Bar Buttons

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
I can use the following to reset the worksheet menu bar.

Code:
Application.CommandBars("Worksheet Menu Bar").Reset

However, sometimes I just want to delete a specific button.

Code:
Application.CommandBars("Worksheet Menu Bar").Controls("Access Scripts").Delete

The problem is, sometimes the Button is not on the menu bar, therefore I need to check first before deleting it.

I can not use reset as there are other buttons that I do not want deleted.

I have tried on error resume next, however it does not work if the button is not on the toolbar, it bugs out.

Does anyone know of an if statement etc... to check if the button is available.

Thanks
 
Phil, provided me with a script which I have adapted to my needs.
Thanks Phil.

http://www.mrexcel.com/forum/showthread.php?p=2938487&posted=1#post2938487


Code:
Sub TEST()
 
    Dim lX As Long
    Dim lY As Long
    Dim sPrintLine As String
    Dim lNextWriteRow As Long
    Dim aryButtonNames() As Variant
 
    lNextWriteRow = 1
 
   bFound = False
    For lX = CommandBars.Count To 1 Step -1
        For lY = 1 To CommandBars(lX).Controls.Count
            If CommandBars(lX).Controls(lY).Caption = "Access Scripts" Or CommandBars(lX).Controls(lY).Caption = "Scripts" Then
                bFound = True
                Exit For
            End If
        Next
        If bFound Then
            CommandBars(lX).Controls(lY).Delete
            bFound = False
        End If
    Next
 
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top