Share via


ControlCollection.AddContentControl Method (ContentControl, String)

Adds a new ContentControl that is based on a native content control in the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function AddContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As ContentControl
ContentControl AddContentControl(
    ContentControl contentControl,
    string name
)

Parameters

  • contentControl
    Type: ContentControl

    The Microsoft.Office.Interop.Word.ContentControl that is the basis for the new control.

Return Value

Type: Microsoft.Office.Tools.Word.ContentControl
The ContentControl that was added to the document.

Exceptions

Exception Condition
ArgumentNullException

contentControl is nulla null reference (Nothing in Visual Basic).

-or-

name is nulla null reference (Nothing in Visual Basic) or has zero length.

ControlNameAlreadyExistsException

A control with the same name is already in the ControlCollection.

ArgumentException

contentControl is not a building block gallery (that is, the Microsoft.Office.Interop.Word.ContentControl.Type property of contentControl does not have the value Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText).

Remarks

Use this method to add a new ContentControl that is based on a native content control in the document at run time. This is useful when you create a ContentControl at run time, and you want to recreate the same control the next time the document is opened. For more information, see Adding Controls to Office Documents at Run Time.

.NET Framework Security

See Also

Reference

ControlCollection Interface

AddContentControl Overload

Microsoft.Office.Tools.Word Namespace