Add Method (CommandBars Collection)

Applies To

CommandBars collection object.

Description

Creates a new command bar and adds it to the collection of command bars. Returns a CommandBar object.

Syntax

expression.Add(Name, Position, MenuBar, Temporary)

expression Required. An expression that returns a CommandBars object.

Name Optional Variant. The name of the new command bar. If this argument is omitted, Word assigns a default name to the command bar (such as "Custom 1").

Position Optional Variant. The position of the new command bar. Can be one of the following MsoBarPosition constants.

Constant

Description

msoBarLeft, msoBarTop, msoBarRight, msoBarBottom

Indicate the left, top, right, and bottom coordinates of the new command bar

msoBarFloating

Indicates that the new command bar won't be docked

msoBarPopup

Indicates that the new command bar will be a shortcut menu

msoBarMenuBar

Indicates that the new command bar will replace the system menu bar on the Macintosh


MenuBar Optional Variant. True to replace the active menu bar with the new command bar. The default value is False.

Temporary Optional Variant. True to make the new command bar temporary. Temporary command bars are deleted when the container application is closed. The default value is False.

See Also

CommandBars collection object, CustomizationContext property.

Example

This example adds a top-level command bar named "Custom" that won't be saved when the session ends. The example also adds a built-in spelling-checker button to the command bar.

Set mybar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, Temporary:=True)
With mybar
    .Controls.Add Type:=msoControlButton, Id:=2
    .Visible = True
End With