共用方式為


Bookmark.Text 屬性 (2007 系統)

更新:2007 年 11 月

取得或設定 Bookmark 控制項中的文字。

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

語法

<BindableAttribute(True)> _
Public Property Text As String

Dim instance As Bookmark
Dim value As String

value = instance.Text

instance.Text = value
[BindableAttribute(true)]
public string Text { get; set; }

屬性值

型別:System.String

Bookmark 控制項的文字。

備註

Text 屬性會傳回書籤內未格式化的純文字。當您設定這個屬性時,便會取代 Bookmark 控制項的文字。

設定 Bookmark.Text 屬性將不會刪除書籤。

在展開多重表格儲存格的書籤中設定 Bookmark.Text 屬性,將只會設定第一個儲存格內的文字。如果這個書籤含有整個表格和周圍的文字,這整個表格便會遭到刪除。

如需設定某個書籤 (會覆蓋另一個書籤) 之 Bookmark.Text 屬性的詳細資訊,請參閱 書籤控制項

範例

下列程式碼範例加入有文字的 Bookmark,然後使用 ComputeStatistics 方法顯示書籤中的字元總數。

這是示範文件層級自訂的範例。

Private Sub BookmarkComputeStatistics()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    Bookmark1.Text = "This is sample bookmark text."

    Dim totalCharacters As Integer = Bookmark1.ComputeStatistics( _
        Word.WdStatistic.wdStatisticCharacters)
    MessageBox.Show("The bookmark contains " & _
        totalCharacters.ToString() & " characters.")

End Sub
private void BookmarkComputeStatistics()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "This is sample bookmark text.";
    int totalCharacters = bookmark1.ComputeStatistics(Word
        .WdStatistic.wdStatisticCharacters);
    MessageBox.Show("The bookmark contains " + 
        totalCharacters.ToString() + " characters.");
}

使用權限

請參閱

參考

Bookmark 類別

Bookmark 成員

Microsoft.Office.Tools.Word 命名空間