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 命名空间