WebListBoxItems.AddItem method (Publisher)

Adds list items to a web list box control.

Syntax

expression.AddItem (Item, Index, SelectState, ItemValue)

expression A variable that represents a WebListBoxItems object.

Parameters

Name Required/Optional Data type Description
Item Required String The name of the item as it appears in the list.
Index Optional Long The number of the list item. If Index is not specified or if it is out of range of the indices of existing list box items, the new item is added to the end of the list box. Otherwise, the new item is inserted at the position specified by Index, and the index position of all the items after it are increased by one.
SelectState Optional Boolean True if the item is selected when the list box is initially displayed. The default value is False.
ItemValue Optional String The value of the list box item. If not specified, the new item's value is the same as the item name.

Remarks

When you programmatically create a new web list box, it contains three items. Use the Delete method to remove them from the list.

Example

This example creates a new list box control in the active publication, removes the three default list items, and then adds several items to it.

Sub AddListBoxItems() 
 Dim intCount As Integer 
 With ActiveDocument.Pages(1).Shapes.AddWebControl _ 
 (Type:=pbWebControlListBox, Left:=100, _ 
 Top:=100, Width:=150, Height:=100) 
 With .WebListBox.ListBoxItems 
 For intCount = 1 To .Count 
 .Delete (1) 
 Next 
 .AddItem Item:="Green" 
 .AddItem Item:="Yellow" 
 .AddItem Item:="Red" 
 .AddItem Item:="Blue" 
 .AddItem Item:="Purple" 
 .AddItem Item:="Chartreuse" 
 .AddItem Item:="Pink" 
 .AddItem Item:="Olive" 
 End With 
 End With 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.