共用方式為


Bookmark.GoTo Method

Gets a Range object that represents the start position of an item within the Bookmark control.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function GoTo ( _
    ByRef What As Object, _
    ByRef Which As Object, _
    ByRef Count As Object, _
    ByRef Name As Object _
) As Range
Range GoTo(
    ref Object What,
    ref Object Which,
    ref Object Count,
    ref Object Name
)

Parameters

  • Count
    Type: System.Object%

    The number of the item in the document. The default value is 1.

    Only positive values are valid. To specify an item that precedes the Bookmark control, use wdGoToPrevious as the Which argument and specify a Count value.

Return Value

Type: Microsoft.Office.Interop.Word.Range
A Range object.

Remarks

When you use the GoTo method with the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant, the Range that is returned includes any grammar error text or spelling error text.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example inserts a Bookmark control with misspelled text to the first paragraph then goes to the first spelling error in the bookmark and displays its position in a message box.

This example is for a document-level customization.

Private Sub BookmarkGoTo()

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

    Dim Range1 As Word.Range = Bookmark1.GoTo( _
        What:=Word.WdGoToItem.wdGoToSpellingError, _
        Which:=Word.WdGoToDirection.wdGoToFirst)

    MessageBox.Show("The first spelling error in Bookmark1 " & _
        "is at position " & Range1.Start.ToString)

End Sub
private void BookmarkGoTo()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
       this.Controls.AddBookmark(this.Paragraphs[1].Range,
       "bookmark1");
    bookmark1.Text = "This bookmark contains spellling erors.";

    object What = Word.WdGoToItem.wdGoToSpellingError;
    object Which = Word.WdGoToDirection.wdGoToFirst;

    Word.Range range1 = bookmark1.GoTo(ref What, ref Which, ref missing, 
        ref missing);

    MessageBox.Show("The first spelling error in bookmark1 is at position " 
        + range1.Start.ToString());
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace