GoTo Method

Applies To

Document object, Range object, Selection object.

Description

Document or Range object: Returns a Range object that represents the start position of the specified item, such as a page, bookmark, or field.

Selection object: Moves the insertion point to the character position immediately preceding the specified item, and returns a Range object (except for the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant).

Note When you use this method with the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant, the Range that's returned includes any grammar error text or spelling error text.

Syntax

expression.GoTo(What, Which, Count, Name)

expression Required. An expression that returns a Document, Range, or Selection object.

What Optional Variant. The kind of item that the range or selection is to be moved to. Can be one of the following WdGoToItem constants.

  • wdGoToBookmark
  • wdGoToComment
  • wdGoToEndnote
  • wdGoToEquation
  • wdGoToField
  • wdGoToFootnote
  • wdGoToGrammaticalError
  • wdGoToGraphic
  • wdGoToHeading
  • wdGoToLine
  • wdGoToObject
  • wdGoToPage
  • wdGoToPercent
  • wdGoToProofreadingError
  • wdGoToSection
  • wdGoToSpellingError
  • wdGoToTable

Which Optional Variant. The item that the range or selection is to be moved to. Can be one of the following WdGoToDirection constants: wdGoToAbsolute, wdGoToFirst, wdGoToLast, wdGoToNext, wdGoToPrevious, or wdGoToRelative.

The following examples are functionally equivalent; they both move the selection to the first heading in the document.

Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1
Count Optional Variant. The number of the item in the document. The default value is 1. The following example moves the selection to the fourth line in the document.

Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=4
Only positive values are valid. To specify an item that precedes the range or selection, use wdGoToPrevious as the Which argument and specify a Count value. The following example moves the selection up two lines.

Selection.GoTo What:=wdGoToLine, Which:=wdGoToPrevious, Count:=2
Name Optional Variant. If the What argument is wdGoToBookmark, wdGoToComment, wdGoToField, or wdGoToObject, this argument specifies a name. The following example moves to the next DATE field.

Selection.GoTo What:=wdGoToField, Name:="Date"
See Also

Browser property, GoBack method, GoForward method, GoToNext method, GoToPrevious method, Move method, Target property.

Example

This example moves the selection to the first cell in the next table.

Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
This example moves the insertion point just before the fifth endnote reference mark in the active document.

If ActiveDocument.Endnotes.Count >= 5 Then
    Selection.GoTo What:=wdGoToEndnote, Which:=wdGoToAbsolute, Count:=5
End If
This example sets R1 equal to the first footnote reference mark in the active document.

If ActiveDocument.Footnotes.Count >= 1 Then
    Set R1 = ActiveDocument.GoTo(What:=wdGoToFootnote, Which:=wdGoToFirst)
    R1.Expand Unit:=wdCharacter
End If
This example moves the selection down four lines.

Selection.GoTo What:=wdGoToLine, Which:=wdGoToRelative, Count:=4
This example moves the selection back two pages.

Selection.GoTo What:=wdGoToPage, Which:=wdGoToPrevious, Count:=2