Bookmark.GoTo(Object, Object, Object, Object) Method

Definition

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

public Microsoft.Office.Interop.Word.Range GoTo (ref object What, ref object Which, ref object Count, ref object Name);
abstract member GoTo : obj * obj * obj * obj -> Microsoft.Office.Interop.Word.Range
Public Function GoTo (Optional ByRef What As Object, Optional ByRef Which As Object, Optional ByRef Count As Object, Optional ByRef Name As Object) As Range

Parameters

What
Object

The kind of item for which the Range is retrieved. Can be one of the WdGoToItem constants.

Which
Object

The item for which the Range is retrieved Can be one of the WdGoToDirection constants.

Count
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.

Name
Object

If the What argument is wdGoToBookmark, wdGoToComment, wdGoToField, or wdGoToObject, this argument specifies a name.

Returns

A Range object.

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 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());
}
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

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.

Applies to