共用方式為


Bookmark.GoToPrevious(WdGoToItem) Method

Definition

Gets a Range object that refers to the start position of the previous item or location in the Bookmark control specified by the What argument.

public:
 Microsoft::Office::Interop::Word::Range ^ GoToPrevious(Microsoft::Office::Interop::Word::WdGoToItem What);
public Microsoft.Office.Interop.Word.Range GoToPrevious (Microsoft.Office.Interop.Word.WdGoToItem What);
abstract member GoToPrevious : Microsoft.Office.Interop.Word.WdGoToItem -> Microsoft.Office.Interop.Word.Range
Public Function GoToPrevious (What As WdGoToItem) As Range

Parameters

What
WdGoToItem

WdGoToItem. The item to be moved to within the Bookmark control.

Returns

A Range object that refers to the start position of the previous item or location in the Bookmark control specified by the What argument.

Examples

The following code example adds text and a Bookmark control with text to the document, and then adds comments to the text. Using GoToNext and GoToPrevious, this code example displays the positions of the comments in a message box.

This example is for a document-level customization.

private void BookmarkGoToNext()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "This is the first paragraph.";
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
       this.Controls.AddBookmark(this.Paragraphs[2].Range,
       "bookmark1");
    bookmark1.Text = "This is original text of the bookmark.";

    object commentText = "This is some comment text.";
    this.Paragraphs[1].Range.Comments.Add(this.Paragraphs[1]
        .Range.Words[4], ref commentText);
    bookmark1.Words.First.Comments.Add(bookmark1.Words.First,
        ref commentText);
    
    bookmark1.InsertBefore("Text inserted before bookmark. ");
    bookmark1.InsertAfter(" Text inserted after bookmark.");
    
    Word.Range range1 = bookmark1.GoToNext(Word.WdGoToItem.wdGoToComment);
    Word.Range range2 = bookmark1.GoToPrevious(Word.WdGoToItem.wdGoToComment);

    MessageBox.Show("Using GoToNext, the comment is at position " 
        + range1.Start.ToString() + "\n" +
        "Using GoToPrevious, the comment is at position "
        + range2.Start.ToString());
}
Private Sub BookmarkGoToNext()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "This is the first paragraph."

    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(2).Range, "Bookmark1")
    Bookmark1.Text = "This is original text of the bookmark."

    Dim commentText As Object = "This is some comment text."
    Me.Paragraphs(1).Range.Comments.Add(Me.Paragraphs(1).Range _
        .Words(4), commentText)
    Bookmark1.Words.First.Comments.Add(Bookmark1.Words.First, _
        commentText)
    Bookmark1.InsertBefore("Text inserted before bookmark. ")
    Bookmark1.InsertAfter(" Text inserted after bookmark.")

    Dim range1 As Word.Range = Bookmark1.GoToNext( _
        Word.WdGoToItem.wdGoToComment)
    Dim range2 As Word.Range = Bookmark1.GoToPrevious( _
        Word.WdGoToItem.wdGoToComment)

    MessageBox.Show("Using GoToNext, the comment is " & _
        "at position " & range1.Start.ToString & vbLf & _
        "Using GoToPrevious, the comment is at position " & _
        range2.Start.ToString)

End Sub

Applies to