Class ContentControlListEntry (Word VBA)
A ContentControlListEntry object represents a list item in a drop-down list or combo box content control. A ContentControlListEntry object is a member of the ContentControlListEntries collection for a ContentControl object. To use a ContentControlListEntry class variable it first needs to be instantiated, for example
Dim ccl as ContentControlListEntry
Set ccl = ActiveDocument.Range.ContentControls(1).DropdownListEntries(Index:=1)
For Each
Here is an example of processing the ContentControlListEntry items in a collection.
Dim cclListEntry As ContentControlListEntry
For Each cclListEntry In ActiveDocument.Range.ContentControls(1).DropdownListEntries
If cclListEntry.Text = "Other" Then cclListEntry.Delete
Next cclDropdownListEntry
Delete
Deletes the specified item in a combo box or drop-down list content control.
Dim objCC As ContentControl
Dim objCL As ContentControlListEntry
For Each objCC In ActiveDocument.ContentControls
If objCC.Type = wdContentControlComboBox Or _
objCC.Type = wdContentControlDropdownList Then
For Each objCL In objCC.DropdownListEntries
If objCL.Text = "Other" Then objCL.Delete
Next
End If
Next
Index
Returns or sets a Long that represents the ordinal position of a content control list item in the collection of list items.
You can set the Index property to any numeric value to change the ordinal position of an item in a list. For example, if you change the Index property for the fifth item in a list to "2", the fifth item becomes the second item. The original second item, and all items that follow, move down one position.
ActiveDocument.Range.ContentControls(1).DropdownListEntries(1).Index =
MoveDown
Moves an item in a drop-down list or combo box content control down one item, so that it is after the item that originally followed it.
Dim objCC As ContentControl
Dim objCL As ContentControlListEntry
Dim intCount As Integer
Set objCC = ActiveDocument.ContentControls.Item(3)
If objCC.Type = wdContentControlComboBox Or _
objCC.Type = wdContentControlDropdownList Then
Set objCL = objCC.DropdownListEntries.Item(1)
For intCount = 1 To objCC.DropdownListEntries.Count
objCL.MoveDown
Next
End If
MoveUp
Moves an item in a drop-down list or combo box content control up one item, so that it is before the item that originally preceded it.
Dim objCC As ContentControl
Dim objCL As ContentControlListEntry
Dim intCount As Integer
Set objCC = ActiveDocument.ContentControls.Item(3)
If objCC.Type = wdContentControlComboBox Or _
objCC.Type = wdContentControlDropdownList Then
Set objCL = objCC.DropdownListEntries.Item(objCC.DropdownListEntries.Count)
For intCount = 1 To objCC.DropdownListEntries.Count
objCL.MoveUp
Next
End If
Select
Selects the list entry in a drop-down list or combo box content control and sets the text of the content control to the value of the item.
Dim objCC As ContentControl
Dim objCE As ContentControlListEntry
Dim objMap As XMLMapping
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList)
objCC.Title = "My Favorite Animal"
If objCC.ShowingPlaceholderText Then _
objCC.SetPlaceholderText , , "Select your favorite animal "
'List entries
objCC.DropdownListEntries.Add "Cat"
objCC.DropdownListEntries.Add "Dog"
objCC.DropdownListEntries.Add "Horse"
objCC.DropdownListEntries.Add "Monkey"
objCC.DropdownListEntries.Add "Snake"
Set objCE = objCC.DropdownListEntries.Add("Other")
objCE.Select
Text
Returns or sets a String that represents the display text of a list item for a drop-down list or combo box content control.
List entries must have unique display names. Attempting to change the Text property to a string that already exists in the list of entries raises a run-time error.
Dim objCC As ContentControl
Dim objLE As ContentControlListEntry
Dim strFirst As String
For Each objCC In ActiveDocument.ContentControls
If objCC.Type = wdContentControlComboBox Or objCC.Type = wdContentControlDropdownList Then
For Each objLE In objCC.DropdownListEntries
strFirst = Left(objLE.Text, 1)
If strFirst = LCase(strFirst) Then
objLE.Text = UCase(strFirst) & Right(objLe.Text, Len(objLe.Text) - 1)
End If
Next
End If
Next
Value
Returns or sets a String that represents the programmatic value of an item in a drop-down list or combo box content control.
Use the Value property to store data that you need to use at processing time. For example, the Text property may contain a string that you want to display and the Value property may contain a number, such as an item number, that you can use to look up information in a database. Also, the value of the Value property is what is sent to the custom XML data, if the content control is mapped to XML data in the data store.
Dim objCc As ContentControl
Dim objLe As ContentControlListEntry
Dim strText As String
Dim strChar As String
Set objCc = ActiveDocument.ContentControls(3)
For Each objLE In objCC.DropdownListEntries
If objLE.Text <> "Other" Then
strText = objLE.Text
objLE.Value = "My favorite animal is the " & strText & "."
End If
Next