Copy Method

Applies To

CommandBarButton object, CommandBarComboBox object, CommandBarControl object, CommandBarPopup object.

Description

Copies the specified command bar control to an existing command bar.

Syntax

expression.Copy(Bar, Before)

expression Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Bar Optional Variant. A CommandBar object that represents the destination command bar. If this argument is omitted, the control is copied to the same command bar (the command bar it's already on).

Before Optional Variant. A number that indicates the position for the new control on the specified command bar. The new control will be inserted before the control at this position. If this argument is omitted, the control is copied to the end of the command bar.

Example

This example copies the first control from the command bar named "Standard" to the command bar named "Custom" and positions it as the first control there too. The example assigns a new parameter to the control and sets the focus to the new button.

Set myCustomBar = CommandBars("Custom")
Set myControl = CommandBars("Standard").Controls(1)
With myControl
    .Copy Bar:=myCustomBar, Before:=1
    .Parameter = "2"
    .SetFocus
End With