ControlCollection.AddContentControl Method

Definition

Overloads

AddContentControl(ContentControl, String)

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

AddContentControl(String, WdContentControlType)

Adds a new ContentControl of the specified type at the current selection in the document.

AddContentControl(Range, String, WdContentControlType)

Adds a new ContentControl of the specified type at the specified range in the document.

AddContentControl(ContentControl, String)

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

public:
 Microsoft::Office::Tools::Word::ContentControl ^ AddContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.ContentControl AddContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.ContentControl
Public Function AddContentControl (contentControl As ContentControl, name As String) As ContentControl

Parameters

contentControl
ContentControl

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

name
String

The name of the new control.

Returns

The ContentControl that was added to the document.

Exceptions

contentControl is null.-or- name is null or has zero length.

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

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.

Applies to

AddContentControl(String, WdContentControlType)

Adds a new ContentControl of the specified type at the current selection in the document.

public:
 Microsoft::Office::Tools::Word::ContentControl ^ AddContentControl(System::String ^ name, Microsoft::Office::Interop::Word::WdContentControlType contentControlType);
public Microsoft.Office.Tools.Word.ContentControl AddContentControl (string name, Microsoft.Office.Interop.Word.WdContentControlType contentControlType);
abstract member AddContentControl : string * Microsoft.Office.Interop.Word.WdContentControlType -> Microsoft.Office.Tools.Word.ContentControl
Public Function AddContentControl (name As String, contentControlType As WdContentControlType) As ContentControl

Parameters

name
String

The name of the new control.

contentControlType
WdContentControlType

One of the Microsoft.Office.Interop.Word.WdContentControlType values that specifies the underlying type of the new content control.

Returns

The ContentControl that was added to the document.

Exceptions

name is null or has zero length.

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

Remarks

Use this method to add a new ContentControl at the current selection in the document at run time. For more information, see Adding Controls to Office Documents at Run Time.

Applies to

AddContentControl(Range, String, WdContentControlType)

Adds a new ContentControl of the specified type at the specified range in the document.

public:
 Microsoft::Office::Tools::Word::ContentControl ^ AddContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name, Microsoft::Office::Interop::Word::WdContentControlType contentControlType);
public Microsoft.Office.Tools.Word.ContentControl AddContentControl (Microsoft.Office.Interop.Word.Range range, string name, Microsoft.Office.Interop.Word.WdContentControlType contentControlType);
abstract member AddContentControl : Microsoft.Office.Interop.Word.Range * string * Microsoft.Office.Interop.Word.WdContentControlType -> Microsoft.Office.Tools.Word.ContentControl
Public Function AddContentControl (range As Range, name As String, contentControlType As WdContentControlType) As ContentControl

Parameters

range
Range

A Range that provides the bounds for the new control.

name
String

The name of the new control.

contentControlType
WdContentControlType

One of the Microsoft.Office.Interop.Word.WdContentControlType values that specifies the underlying type of the new content control.

Returns

The ContentControl that was added to the document.

Exceptions

name is null or has zero length.

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

Remarks

Use this method to add a new ContentControl at a specified range in the document at run time. For more information, see Adding Controls to Office Documents at Run Time.

Applies to