AddItem Method

Microsoft Office Visual Basic

Adds a list item to the specified command bar combo box control. The combo box control must be a custom control and must be a drop-down list box or a combo box.

Note  This method will fail if it's applied to an edit box or a built-in combo box control.

expression.AddItem(Text, Index)

expression    Required. An expression that returns a CommandBarComboBox object.

Text    Required String. The text added to the control.

Index    Optional Variant. The position of the item in the list. If this argument is omitted, the item is added to the end of the list.

Example

This example adds a combo box control to a command bar. Two items are added to the control, and the number of line items and the width of the combo box are set.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls.Add(Type:=msoControlComboBox, Id:=1)
With myControl
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
End With