Expand Minimize

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)

Range GoTo(
	ref Object What,
	ref Object Which,
	ref Object Count,
	ref Object Name
)

Parameters

What
Type: System.Object

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

Which
Type: System.Object

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

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.

Name
Type: System.Object

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

Return Value

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

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.

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft