Export (0) Print
Expand All
Expand Minimize

Document.SelectContentControlsByTag Method (2007 System)

Returns all the content controls in the document that have the specified tag.

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

public ContentControls SelectContentControlsByTag(
	string Tag


Type: System.String

The tag of the content controls to return.

Return Value

Type: ContentControls
A ContentControls collection that contains the content controls that have the specified tag.

The following code example adds three paragraphs to the document and then adds one control to each new paragraph: a RichTextContentControl, a ComboBoxContentControl, and a DropDownListContentControl. The example sets the Tag and Title properties of each control. Next, the code calls the SelectContentControlsByTag method to get the collection of native content controls whose tag value equals Customer and then displays the title of each control from the returned collection in a message box.

This example is for a document-level customization.

private void ContentControlsTag()
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl =
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

    Word.Paragraph par2 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl =
    comboBoxControl.Tag = "Customer";
    comboBoxControl.Title = "Customer Title";

    Word.Paragraph par3 = this.Paragraphs.Add(ref missing);
        dropDownListControl = this.Controls.AddDropDownListContentControl(
        par3.Range, "dropDownListControl");
    dropDownListControl.Tag = "Products";
    dropDownListControl.Title = "List of Products";

    Word.ContentControls relatedControls = 
    MessageBox.Show("Displaying all controls with a Tag value of" + 
        " 'Customer'. Click OK to continue.");
    foreach (Word.ContentControl ctrl in relatedControls)
        MessageBox.Show("Control title: " + ctrl.Title);

Community Additions

© 2014 Microsoft