Class ContentControl (Word VBA)

An individual content control. 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 contents such as dates, lists, or paragraphs of formatted text. The ContentControl object is a member of the ContentControls collection.

The main procedures of class ContentControl are Copy, Delete and ContentControls.Add

Set

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

Dim ccl as ContentControl
Set ccl = ActiveDocument.Range.ContentControls(Index:=1)

The following procedures can be used to set variables of type ContentControl: ParentContentControl, ContentControls.Add, ContentControls.Item, Range.ParentContentControl, Document.ContentControls, Document.SelectContentControlsByTag, Document.SelectContentControlsByTitle, Document.SelectLinkedControls, Document.SelectUnlinkedControls and Range.ContentControls

For Each

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

Dim ccl As ContentControl
For Each ccl In ActiveDocument.Range.ContentControls
	
Next ccl

Themes

The following procedures in this class have been grouped together and are described on a separate theme page

Format with its procedures Color, DateDisplayFormat, DateStorageFormat and DefaultTextStyle

Methods

These are the main methods of the ContentControl class

Copy - Copies the content control from the active document to the Clipboard.

ActiveDocument.Range.ContentControls(1).Copy

Delete - Deletes the specified content control and the contents of the content control.

ActiveDocument.Range.ContentControls(1).Delete

ContentControls.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.

Dim ccl As ContentControl
Set ccl = ActiveDocument.Range.ContentControls.Add()

Other Methods

SetCheckedSymbol - Sets the symbol used to represent the checked state of a check box content control.

Dim lngCharacterNumber As Long: lngCharacterNumber =  
ActiveDocument.Range.ContentControls(1).SetCheckedSymbol CharacterNumber:=lngCharacterNumber

SetPlaceholderText - Sets the placeholder text that displays in the content control until a user enters their own text.

ActiveDocument.Range.ContentControls(1).SetPlaceholderText

SetUncheckedSymbol - Sets the symbol used to represent the unchecked state of a check box content control.

Dim lngCharacterNumber As Long: lngCharacterNumber =  
ActiveDocument.Range.ContentControls(1).SetUncheckedSymbol CharacterNumber:=lngCharacterNumber

Properties

AllowInsertDeleteSection gets or sets whether users can add or remove sections from the specified repeating section content control by using the user interface.

ActiveDocument.Range.ContentControls(1).AllowInsertDeleteSection = True

Appearance returns or sets the appearance of the content control.

ActiveDocument.Range.ContentControls(1).Appearance = wdContentControlBoundingBox

BuildingBlockCategory returns or sets a String that represents the category for a building block content control.

ActiveDocument.Range.ContentControls(1).BuildingBlockCategory =

BuildingBlockType returns or sets a WdBuildingBlockTypes constant that represents they type of building block for a building block content control.

ActiveDocument.Range.ContentControls(1).BuildingBlockType = wdTypeAutoText

Checked returns or sets a Boolean that represents the current state (checked/unchecked) for a check box.

ActiveDocument.Range.ContentControls(1).Checked = True

DateCalendarType returns or sets a WdCalendarType constant that represents the calendar type for a calendar content control.

ActiveDocument.Range.ContentControls(1).DateCalendarType = wdCalendarArabic

DateDisplayLocale returns a WdLanguageID that represents the language format for the date displayed in a date content control.

ActiveDocument.Range.ContentControls(1).DateDisplayLocale = wdAfrikaans

DropdownListEntries returns a ContentControlListEntries collection that represents the items in a drop-down list content control or in a combo box content control.

Dim cclsDropdownListEntries As ContentControlListEntries
Set cclsDropdownListEntries = ActiveDocument.Range.ContentControls(1).DropdownListEntries

ID returns a String that represents the identification for a content control.

Dim strID As String
strID = ActiveDocument.Range.ContentControls(1).ID

Level returns the level of the content control—whether the content control surrounds text, paragraphs, table cells, or table rows; or if it is inline.

Dim wccLevel As WdContentControlLevel
wccLevel = ActiveDocument.Range.ContentControls(1).Level

LockContentControl returns or sets a Boolean that represents whether the user can delete a content control from the active document.

ActiveDocument.Range.ContentControls(1).LockContentControl = True

LockContents returns or sets a Boolean that represents whether the user can edit the contents of a content control.

ActiveDocument.Range.ContentControls(1).LockContents = True

MultiLine returns a Boolean that represents whether a text content control allows multiple lines of text.

ActiveDocument.Range.ContentControls(1).MultiLine = True

Parent returns an object that represents the parent object of the specified ContentControl object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.ContentControls(1).Parent

ParentContentControl returns a ContentControl that represents the parent content control for a content control that is nested inside a rich-text control or group control.

Dim cclParentContentControl As ContentControl
Set cclParentContentControl = ActiveDocument.Range.ContentControls(1).ParentContentControl

PlaceholderText returns a BuildingBlock object that represents the placeholder text for a content control.

Dim bbkPlaceholderText As BuildingBlock
Set bbkPlaceholderText = ActiveDocument.Range.ContentControls(1).PlaceholderText

Range returns a Range that represents the contents of the content control in the active document.

Dim rngRange As Range
Set rngRange = ActiveDocument.Range.ContentControls(1).Range

RepeatingSectionItems returns the collection of repeating section items in the specified repeating section content control.

Dim rsiRepeatingSectionItems As RepeatingSectionItemColl
Set rsiRepeatingSectionItems = ActiveDocument.Range.ContentControls(1).RepeatingSectionItems

RepeatingSectionItemTitle returns or sets the name of the repeating section items used in the context menu associated with the specified repeating section content control.

ActiveDocument.Range.ContentControls(1).RepeatingSectionItemTitle =

ShowingPlaceholderText returns a Boolean that indicates whether the placeholder text for the content control is displayed.

Dim booShowingPlaceholderText As Boolean
booShowingPlaceholderText = ActiveDocument.Range.ContentControls(1).ShowingPlaceholderText

Tag returns or sets a String that represents a value to identify a content control.

ActiveDocument.Range.ContentControls(1).Tag =

Temporary returns or sets a Boolean that represents whether to remove a content control from the active document when the user edits the contents of the control.

ActiveDocument.Range.ContentControls(1).Temporary = True

Title returns or sets a String that represents the title for a content control.

ActiveDocument.Range.ContentControls(1).Title =

Type returns or sets a WdContentControlType that represents the type for a content control.

ActiveDocument.Range.ContentControls(1).Type = wdContentControlBuildingBlockGallery

XMLMapping returns an XMLMapping object that represents the mapping of a content control to XML data in the data store of a document.

Dim xmlXMLMapping As XMLMapping
Set xmlXMLMapping = ActiveDocument.Range.ContentControls(1).XMLMapping

ContentControls.Count returns the number of items in the ContentControls collection.

Dim lngCount As Long
lngCount = ActiveDocument.Range.ContentControls.Count

ContentControls.Parent returns an object that represents the parent object of the specified ContentControls object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.ContentControls.Parent