Name
commandbarcombobox
.AddItem(Text
, [Index
])
Synopsis
Adds an item to the control’s list.
Argument |
Settings |
---|---|
|
The item to add to the list. |
|
The position of the item in the list. The default is to insert the new item at the end of the list. |
The following code creates a new drop-down list on the worksheet menu bar and adds three items to the list:
Sub AddDropDown( ) Dim cb As CommandBar, cbo As CommandBarComboBox ' Get a command bar Set cb = CommandBars("Worksheet Menu Bar") ' Create the combo box. Set cbo = cb.Controls.Add(msoControlDropdown, , , , True) ' Add a Tag so this control can be found from other code. cbo.Tag = "cboSelectText" ' Add items. cbo.AddItem "This" cbo.AddItem "That" cbo.AddItem "the" cbo.AddItem "other" ' Set the procedure to run. cbo.OnAction = "ShowSelection" End Sub
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.