Skip to main content

CommandBars object

Table of contents
  1. Example

A collection of CommandBar objects that represent the command bars in the container application.

Example

Use the CommandBars property to return the CommandBars collection. The following example displays in the Immediate window both the name and local name of each menu bar and toolbar, and it displays a value that indicates whether the menu bar or toolbar is visible.

For Each cbar in CommandBars 
    Debug.Print cbar.Name, cbar.NameLocal, cbar.Visible 
Next

Use the Add method to add a new command bar to the collection. The following example creates a custom toolbar named Custom1 and displays it as a floating toolbar.

Set cbar1 = CommandBars.Add(Name:="Custom1", Position:=msoBarFloating) 
cbar1.Visible = True

Use enumName, where index is the name or index number of a command bar, to return a single CommandBar object. The following example docks the toolbar named Custom1 at the bottom of the application window.

CommandBars("Custom1").Position = msoBarBottom

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>