Class ContentControls (Word VBA)
A collection of ContentControl objects. Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Individual content controls may contain content such as dates, lists, or paragraphs of formatted text. To use a ContentControls class variable it first needs to be instantiated, for example
Dim ccs as ContentControls
Set ccs = ActiveDocument.Range.ContentControls
For Each
Here is an example of processing the ContentControls items in a collection.
Dim ccl As ContentControl
For Each ccl In ActiveDocument.Range.ContentControls
Next ccl
Add
Adds a new content control, of the type specified, into the active document and returns a ContentControl object that represents the new content control.
You can nest content controls only within rich-text content controls, building block gallery content controls, and group content controls. If the insertion point or current selection is inside a content control of a different type, this method raises an error. In this case, you can either move the insertion point or use the Range parameter to specify a location within the document.
Dim objCC As ContentControl
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"
objCC.DropdownListEntries.Add "Other"
Arguments
Optional arguments
The following arguments are optional
Type (WdContentControlType) - Specifies the type of content control to insert into the active document. If omitted, Microsoft Word inserts a rich-text content control.
Here you can find possible values for
Range (Range) - Specifies where in the active document to place the content control. If omitted, Word places the content control at the position of the insertion point or replaces the current selection.
Count
Returns the number of items in the ContentControls collection.
Dim lngCount As Long
lngCount = ActiveDocument.Range.ContentControls.Count
Item
Returns a ContentControl object that represents the specified content control within the collection of content controls in a document.
Item (Index)
Index: Specifies the ordinal position of the content control to return.
Dim ccl As ContentControl
Set ccl = ActiveDocument.Range.ContentControls(Index:=1)