Class ListEntry (Word VBA)

The class ListEntry represents an item in a drop-down form field. The ListEntry object is a member of the ListEntries collection. The ListEntries collection includes all the items in a drop-down form field.

Set

To use a ListEntry class variable it first needs to be instantiated, for example

Dim ley as ListEntry
Set ley = ActiveDocument.FormFields(1).DropDown.ListEntries(Index:=1)

The following procedures can be used to set variables of type ListEntry: DropDown.ListEntries, ListEntries.Add and ListEntries.Item

For Each

Here is an example of processing the ListEntry items in a collection.

Dim ley As ListEntry
For Each ley In ActiveDocument.FormFields(1).DropDown.ListEntries
	
Next ley

ListEntries.Add

Returns a ListEntry object that represents an item added to a drop-down form field.

Syntax : expression.Add (Name, Index)

Set myField = ActiveDocument.FormFields.Add(Range:= _ 
 Selection.Range, Type:= wdFieldFormDropDown) 
With myField.DropDown.ListEntries 
 .Add Name:="Red" 
 .Add Name:="Blue" 
 .Add Name:="Green" 
End With

Arguments

The following argument is required

Name (String) - The name of the drop-down form field item.

The following argument is optional

Index (Long) - A number that represents the position of the item in the list.

ListEntries.Clear

Removes all items from a drop-down form field.

Documents("Sales.doc").FormFields("Colors") _ 
 .DropDown.ListEntries.Clear

ListEntries.Count

Returns a Long that represents the number of list entries in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.FormFields(1).DropDown.ListEntries.Count

ListEntries.Item

Returns an individual ListEntry object in a collection.

Syntax : expression.Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.

Sub ListEntryItem() 
 Dim d As DropDown 
 Set d = ActiveDocument.FormFields.Add _ 
 (Range:=Selection.Range, _ 
 Type:=wdFieldFormDropDown).DropDown 
 With d.ListEntries 
 .Add Name:="Black" 
 .Add Name:="Green" 
 End With 
 MsgBox d.ListEntries.Item(1).Name 
End Sub

ListEntries.Parent

Returns an object that represents the parent object of the specified ListEntries object.

Dim objParent As Object
Set objParent = ActiveDocument.FormFields(1).DropDown.ListEntries.Parent

Delete

Deletes the specified list entry.

ActiveDocument.FormFields(1).DropDown.ListEntries(1).Delete

Index

Returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveDocument.FormFields(1).DropDown.ListEntries(1).Index

Name

Returns or sets the name of the specified object.

ActiveDocument.FormFields(1).DropDown.ListEntries(1).Name =

Parent

Returns an object that represents the parent object of the specified ListEntry object.

Dim objParent As Object
Set objParent = ActiveDocument.FormFields(1).DropDown.ListEntries(1).Parent