FindControl Method

Microsoft Office Object Model

FindControl Method

       

Returns a CommandBarControl object that fits a specified criteria.

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

expression   Required. An expression that returns a CommandBars object.

Type   Optional MsoControlType. The type of control.

MsoControlType type can be one of these MsoControlType constants.
msoControlActiveX
msoControlCustom
msoControlButton
msoControlEdit
msoControlDropdown
msoControlComboBox
msoControlButtonDropdown
msoControlSplitDropdown
msoControlGenericDropdown
msoControlGraphicCombo
msoControlSplitButtonMRUPopup
msoControlSplitExpandingGrid
msoControlGraphicDropdown
msoControlPopup
msoControlGraphicPopup
msoControlButtonPopup
msoControlGauge
msoControlLabel
msoControlExpandingGrid
msoControlGrid
msoControlOCXDropDown
msoControlSplitButtonPopup
msoControlPane

Id   Optional Variant. The identifier of the control.

Tag   Optional Variant. The tag value of the control.

Visible    Optional Variant. True to include only visible command bar controls in the search. The default value is False. Visible command bars include all visible toolbars and any menus that are open at the time the FindControl method is executed.

Recursive    Optional Boolean. True to include the command bar and all of its pop-up subtoolbars in the search. This argument only applies to the CommandBar object. The default value is False.

Remarks

If the CommandBars collection contains two or more controls that fit the search criteria, FindControl returns the first control that's found. If no control that fits the criteria is found, FindControl returns Nothing.

Example

This example finds the first control on the command bar named “Custom”. If the control is a button, the example uses the FindControl method to find the Copy button (on the Standard toolbar) and then copies the face from the Copy button and pastes it onto the control.

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