FindControl Method

Applies To

CommandBar object, CommandBars collection object.

Description

Returns a CommandBarControl object that fits the specified criteria.

Syntax

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

expression Required. An expression that returns a CommandBars object.

Type Optional Variant. The type of control to be searched for. Can be one of the following MsoControlType constants:

msoControlButton

msoControlButtonDropdown

msoControlButtonPopup

msoControlComboBox

msoControlCustom

msoControlDropdown

msoControlEdit

msoControlExpandingGrid

msoControlGauge

msoControlGenericDropdown

msoControlGraphicCombo

msoControlGraphicDropdown

msoControlGraphicPopup

msoControlGrid

msoControlLabel

msoControlOCXDropDown

msoControlPopup

msoControlSplitButtonMRUPopup

msoControlSplitButtonPopup

msoControlSplitDropdown

msoControlSplitExpandingGrid


Id Optional Variant. The identifier of the control to be searched for.

Tag Optional Variant. The tag value of the control to be searched for.

Visible Optional Variant. True to include only visible command bar controls in the search. The default value is False.

Recursive Optional Boolean. True to include the command bar and all of its popup sub-toolbars in the search. 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. None of the arguments for the FindControl method have a default value.

Example

This example adds the Save button to the Help menu on the menu bar. Using the FindControl method ensures that the Help menu will be found even if the user has customized the menu bar.

Set helpMenu = CommandBars.FindControl _
    (Type:=msoControlPopup, Id:=helpId)
Set helpMenuDrop = helpMenu.Control.CommandBar
helpMenuDrop.Controls.Add Type:=msoControlButton, Id:=saveId