SetFocus Method

Applies To

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

Description

Moves the keyboard focus to the specified command bar control so that it can receive keyboard input. The kind of keyboard input you can direct to the control depends on what type of control it is.

Note If the control is disabled or isn't visible from the current state, this method will fail.

Syntax

expression.SetFocus

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

Example

This example copies the fourth control from the My Custom Bar custom command bar and pastes it onto the same command bar as the first control. The example also assigns a new parameter to the control and sets the focus to the new button.

Set mycontrol = CommandBars("My Custom Bar").Controls(4)
With mycontrol
    .Copy Before:=1
    .Parameter = "2"
    .SetFocus
End With