Share via


Bookmark.MoveEnd 方法

移動 Bookmark 控制項的結束字元位置。

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

語法

'宣告
Function MoveEnd ( _
    ByRef unit As Object, _
    ByRef count As Object _
) As Integer
int MoveEnd(
    ref Object unit,
    ref Object count
)

參數

  • unit
    型別:System.Object%
    用以移動結束字元位置的單元。
  • count
    型別:System.Object%
    要移動的單元數。如果這個數是正數,則文件中的結束字元位置會向前移動。如果這個數是負數,則結尾會向後移動。如果結束位置超過起始位置,範圍會摺疊起來,且兩個字元位置會一起移動。預設值為 1。

傳回值

型別:System.Int32
Bookmark 控制項真正移動的單元數目,或如果移動不成功便會傳回 0 (零)。

備註

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例將有文字的 Bookmark 控制項加入至第一個段落,並在訊息方塊中顯示書籤的最後一個字。 然後程式碼會呼叫 MoveEnd 方法,並在新的訊息方塊中顯示書籤的最後一個字。

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

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

    MessageBox.Show("Last word of bookmark prior to calling MoveEnd: " _
        & Bookmark1.Words.Last.Text)

    Bookmark1.MoveEnd(Word.WdUnits.wdWord, 1)

    MessageBox.Show("Last word of bookmark after calling MoveEnd: " _
        & Bookmark1.Words.Last.Text)
End Sub
private void BookmarkMoveEnd()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "This is sample text.";
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range.Words[3],
        "bookmark1");

    object Unit = Word.WdUnits.wdWord;
    object Count = 1;

    MessageBox.Show("Last word of bookmark prior to calling MoveEnd: "
        + bookmark1.Words.Last.Text);

    bookmark1.MoveEnd(ref Unit, ref Count);

    MessageBox.Show("Last word of bookmark after calling MoveEnd: "
        + bookmark1.Words.Last.Text);

}

.NET Framework 安全性

請參閱

參考

Bookmark 介面

Microsoft.Office.Tools.Word 命名空間