CommandBarControl.SetFocus 方法 (Office)CommandBarControl.SetFocus Method (Office)

将键盘焦点移动到指定的 CommandBarControl。Moves the keyboard focus to the specified CommandBarControl. 如果该控件被禁用,或不可见,则此方法将失败。If the control is disabled or isn't visible, this method will fail.

备注

在某些 Microsoft Office 应用程序使用 CommandBars 已取代的 Microsoft Office Fluent 用户界面的新功能区组件。The use of CommandBars in some Microsoft Office applications has been superseded by the new ribbon component of the Microsoft Office Fluent user interface. 有关详细信息,搜索帮助关键字"功能区"。For more information, search Help for the keyword "ribbon."

语法Syntax

expressionexpression. SetFocus

_表达式_一个代表CommandBarControl对象的变量。expression A variable that represents a CommandBarControl object.

说明Remarks

在控件上的重点是不明显。The focus on the control is subtle. 使用此方法后,您会注意到三个维度突出显示在控件上的。After you use this method, you will notice a three dimensional highlight on the control. 按箭头键将导航工具栏,就好像您已经按键盘控制到达在控件。Pressing the arrow keys will navigate in the toolbars, as if you had arrived at the control by pressing only keyboard controls.

示例Example

此示例创建名为"Custom"的命令栏,并向其添加一个组合框控件和Button控件。This example creates a command bar named "Custom" and adds a ComboBox control and a Button control to it. 该示例使用SetFocus方法将焦点设置到ComboBox控件。The example then uses the SetFocus method to set the focus to the ComboBox control.

Set focusBar = CommandBars.Add(Name:="Custom") 
With CommandBars("Custom") 
    .Visible = True  
    .Position = msoBarTop 
End With 
 
Set testComboBox = CommandBars("Custom").Controls _ 
    .Add(Type:=msoControlComboBox, ID:=1) 
With testComboBox 
    .AddItem "First Item", 1 
    .AddItem "Second Item", 2 
End With 
Set testButton = CommandBars("Custom").Controls _ 
    .Add(Type:=msoControlButton) 
testButton.FaceId = 17 
' Set the focus to the combo box. 
testComboBox.SetFocus

另请参阅See also

CommandBarControl 对象CommandBarControl Object

CommandBarControl 对象成员CommandBarControl Object Members