Microsoft Office 2000/Visual Basic Programmer's Guide   

Deleting a Command Bar

You can delete toolbars and menu bars from the Customize dialog box or by using VBA. You can delete pop-up menus only by using VBA. Use the Delete method of the CommandBars collection to remove an existing command bar from the collection. The following procedure illustrates one way to delete a CommandBar object:

Function CBDeleteCommandBar(strCBarName As String) As Boolean
   On Error Resume Next
   Application.CommandBars(strCBarName).Delete
End Function

The CBDeleteCommandBar procedure is available in the modCommandBarCode module in CommandBarSamples.mdb in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM.

Note that an error will occur if strCBarName is not the name of an existing command bar. The procedure uses the On Error Resume Next statement to ignore this error because if an error occurs, it means there is nothing to delete.