共用方式為


DocumentBase.SelectContentControlsByTitle 方法

傳回文件中具有特定標題的所有內容控制項。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public Function SelectContentControlsByTitle ( _
    title As String _
) As ContentControls
public ContentControls SelectContentControlsByTitle(
    string title
)

參數

  • title
    型別:System.String
    要傳回之內容控制項的標題。

傳回值

型別:Microsoft.Office.Interop.Word.ContentControls
ContentControls 集合,包含具有指定之標題的內容控制項。

範例

下列程式碼範例會在此文件中加入兩個段落,然後在每個新段落中各加入一個控制項:RichTextContentControlComboBoxContentControl。 這個範例會設定每個控制項的 Tag 和 Title 屬性。 接下來,程式碼會呼叫 SelectContentControlsByTitle 方法,取得標題等於 Customer Title 之原生內容控制項的集合, 然後修改所傳回集合中之每個控制項的預留位置文字,在本例中,該預留位置文字只包含 ComboBoxContentControl。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub ContentControlsTitle()
    Dim par1 As Word.Paragraph = Me.Paragraphs.Add()
    Dim richTextControl As Microsoft.Office.Tools.Word.RichTextContentControl _
        = Me.Controls.AddRichTextContentControl(par1.Range, "richTextControl")
    richTextControl.Tag = "Customer"
    richTextControl.Title = "Customer Name"

    Dim par2 As Word.Paragraph = Me.Paragraphs.Add()
    Dim comboBoxControl As Microsoft.Office.Tools.Word.ComboBoxContentControl _
        = Me.Controls.AddComboBoxContentControl(par2.Range, "comboBoxControl")
    comboBoxControl.Tag = "Customer"
    comboBoxControl.Title = "Customer Title"

    Dim myControls As Word.ContentControls = _
        Me.SelectContentControlsByTitle("Customer Title")
    For Each ctrl As Word.ContentControl In myControls
        ctrl.SetPlaceholderText(Text:="Select a title.")
    Next
End Sub
private void ContentControlsTitle()
{                        
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl = 
        this.Controls.AddRichTextContentControl(par1.Range, 
        "richTextControl");
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

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

    Word.ContentControls myControls = 
        this.SelectContentControlsByTitle("Customer Title");
    foreach (Word.ContentControl ctrl in myControls)
    {                                
        ctrl.SetPlaceholderText(null, null, "Select a title.");                
    }
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間