Export (0) Print
Expand All

Creating a Command Bar

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You can create toolbars by using the Customize dialog box or by using Microsoft® Visual Basic® for Applications (VBA) code in any Microsoft® Office application. In Microsoft® Access, you also can create menu bars and pop-up menus by using the Customize dialog box. However, in all other Office applications, you must use VBA code to create menu bars or pop-up menus.

You create a custom command bar by using the CommandBars collection's Add method. The Add method creates a toolbar by default. To create a menu bar or pop-up menu, use the msoBarMenuBar or msoBarPopup constant in the Add method's Position argument. The following code sample illustrates how to create all three types of CommandBar objects:

Dim cbrCmdBar       As CommandBar
Dim strCBarName     As String

' Create a toolbar.
strCBarName = "MyNewToolbar"
Set cbrCmdBar = Application.CommandBars.Add(Name:=strCBarName)

' Create a menu bar.
strCBarName = "MyNewMenuBar"
Set cbrCmdBar = Application.CommandBars _
   .Add(Name:=strCBarName, Position:=msoBarMenuBar)

' Create a pop-up menu.
strCBarName = "MyNewPopupMenu"
Set cbrCmdBar = Application.CommandBars _
   .Add(Name:=strCBarName, Position:=msoBarPopup)

After you have created a command bar, you still must add any controls that you want and set the command bar's Visible property to True.

See Also

Working with Command Bars | Manipulating Command Bars and Command Bar Controls with VBA Code | Getting Information About Command Bars and Controls | Hiding and Showing a Command Bar | Copying a Command Bar | Deleting a Command Bar | Preventing Users from Modifying Custom Command Bars | Working with Personalized Menus | Working with Images on Command Bar Buttons | Working with Command Bar Controls | Working with Command Bar Events

Show:
© 2014 Microsoft