Microsoft Office 2000/Visual Basic Programmer's Guide   

Hiding and Showing a Command Bar

You hide or show a toolbar by using the CommandBar object's Visible property. When you display a toolbar, you can specify where it will appear on the screen by using the Position property. For example, the following code sample takes three arguments: the name of a toolbar, a Boolean value indicating whether it should be visible or hidden, and a value matching an msoBarPosition constant specifying where on the screen the toolbar should be displayed. The sample code also illustrates how to use the CommandBar object's Type property to make sure the specified command bar is a toolbar:

Function CBToolbarShow(strCBarName As String, _
                       blnVisible As Boolean, _
                       Optional lngPosition As Long = msoBarTop) As Boolean
                  
   ' This procedure displays or hides the command bar specified in the
   ' strCBarName argument according to the value of the blnVisible
   ' argument. The optional lngPosition argument specifies where the
   ' command bar will appear on the screen.
   
   Dim cbrCmdBar As CommandBar
      
   On Error GoTo CBToolbarShow_Err
   
   Set cbrCmdBar = Application.CommandBars(strCBarName)
   
   ' Show only toolbars.
   If cbrCmdBar.Type > msoBarTypeNormal Then
      CBToolbarShow = False
      Exit Function
   End If
   ' If Position argument is invalid, set to the default
   ' msoBarTop position.
   If lngPosition < msoBarLeft Or lngPosition > msoBarMenuBar Then
      lngPosition = msoBarTop
   End If
   
   With cbrCmdBar
      .Visible = blnVisible
      .Position = lngPosition
   End With
   
   CBToolbarShow = True

CBToolbarShow_End:
   Exit Function
CBToolbarShow_Err:
   CBToolbarShow = False
   Resume CBToolbarShow_End
End Function

The CBToolbarShow 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.

You display a custom menu bar by setting its Visible property to True and setting the existing menu bar's Visible property to False. To see an example of a procedure that displays a menu bar, see the CBMenuBarShow procedure in the modCommandBarCode module in the CommandBarSamples.mdb file in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM.