目录

FindControl 方法

优质
小牛编辑
125浏览
2023-12-01

返回一个符合指定条件的CommandBarControl 对象。

expression.FindControl(Type,Id,Tag,Visible, Recursive)

expression 必需。该表达式返回一个CommandBars 对象。

TypeMsoControlType 类型,可选。要查找的控件类型。

MsoControlType 类型可为以下 MsoControlType 常量之一:msoControlActiveXmsoControlCustommsoControlButtonmsoControlEditmsoControlDropdownmsoControlComboBoxmsoControlButtonDropdownmsoControlSplitDropdownmsoControlGenericDropdownmsoControlGraphicCombomsoControlSplitButtonMRUPopupmsoControlSplitExpandingGridmsoControlGraphicDropdownmsoControlPopupmsoControlGraphicPopupmsoControlButtonPopupmsoControlGaugemsoControlLabelmsoControlExpandingGridmsoControlGridmsoControlOCXDropDownmsoControlSplitButtonPopupmsoControlPane

IdVariant 类型,可选。要查找的控件的标识符。

TagVariant 类型,可选。要查找的控件的标记值。

VisibleVariant 类型,可选。如果该值为True,那么只查找屏幕上显示的命令栏控件。默认值为False。屏幕上可见的命令栏,其中包括执行FindControl 方法时所打开的所有可见的工具栏和菜单。

RecursiveBoolean 类型,可选。如果该值为True,那么将在命令栏及其全部弹出式子工具栏中查找。此参数仅应用于CommandBar 对象。默认值为False

说明

如果CommandBars 集合中有两个或者更多的控件符合搜索条件,那么FindControl 返回找到的第一个控件。如果没有控件符合搜索条件,那么FindControl 返回Nothing

示例

本示例可实现的功能为:在命令栏“Custom”中查找第一个控件。如果该控件是按钮,那么示例将用FindControl 方法查找Copy 按钮(位于“常用”工具栏上),然后复制Copy 按钮的图符并粘贴到该控件上。

Set oldCtrl = CommandBars("Custom").Controls(1)
If oldCtrl.Type = 1 Then
 Set newCtrl = CommandBars.FindControl(Type:= _
 MsoControlButton, ID:= _
 CommandBars("Standard").Controls("Copy").ID)
 NewCtrl.CopyFace
 OldCtrl.PasteFace
End If