Removing custom toolbar

C

Chris Watts

I have created a Custom Toolbar using vba, in Excel 2007. Now I cannot find
a way to delete it! Help!!

The code that created it is:
With Application.CommandBars.Add
.Name = "WO 119"
.Visible = True
End With

Using either of the doesn't remove/kill it!

DeleteCommandBarControl "WO 119"
Application.CommandBars("WO 119").Delete


TIA
Chris
 
S

Steve Rindsberg

I have created a Custom Toolbar using vba, in Excel 2007. Now I cannot find
a way to delete it! Help!!

The code that created it is:
With Application.CommandBars.Add
.Name = "WO 119"
.Visible = True
End With

Here that gives me an invisible toolbar. There's no evidence that it worked.

If you add a button to the toolbar you'll be able to at least see the new
toolbar.

With Application.CommandBars("WO 119").Controls.Add(msoControlButton)
.Caption = "Hi there!"
.Visible = True
.FaceId = 42
End With

Using either of the doesn't remove/kill it!

DeleteCommandBarControl "WO 119"
Application.CommandBars("WO 119").Delete

The last one works, but of course, if the toolbar's not visible, you can't
tell whether the Delete worked or not. ;-)
 
C

Chris Watts

Steve Rindsberg said:
Here that gives me an invisible toolbar. There's no evidence that it
worked.

If you add a button to the toolbar you'll be able to at least see the new
toolbar.

With Application.CommandBars("WO 119").Controls.Add(msoControlButton)
.Caption = "Hi there!"
.Visible = True
.FaceId = 42
End With



The last one works, but of course, if the toolbar's not visible, you can't
tell whether the Delete worked or not. ;-)


Thanks Steve - once more I am greatful to you for your advice etc.
It was visible all the time.
In the end I got rid of it by brute force and ignorance - by scanning .Index
until I found the corresponding .Name and then deleted it using the Index

I now have a more robust way of handling the problem with multiple custom
menus. For what it is worth I now use:

Option Explicit
Dim cb As CommandBar

Sub RemoveMenubar()
On Error Resume Next
For Each cb In CommandBars
Select Case cb.Name
Case "WO 119 a", "WO 119 b", "WO 119 c", "WO 119 Button1", "WO 119
Button2"
cb.Delete
End Select
Next
On Error GoTo 0
End Sub

cheers
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top