Range.GoTo Method (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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

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

expression Required. A variable that represents a Range object.

Parameters

Name

Required/Optional

Data Type

Description

What

Optional

Variant

The kind of item to which the range is moved. Can be one of the WdGoToItem constants.

Which

Optional

Variant

The item to which the range is moved. Can be one of the WdGoToDirection constants.

Count

Optional

Variant

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 range, use wdGoToPrevious as the Which argument and specify a Count value.

Name

Optional

Variant

If the What argument is wdGoToBookmark, wdGoToComment, wdGoToField, or wdGoToObject, this argument specifies a name. Only positive values are valid. To specify an item that precedes the range, use wdGoToPrevious as the Which argument and specify a Count value.

The following example moves the range up two lines.

ActiveDocument.Range.GoTo What:=wdGoToLine, Which:=wdGoToPrevious, Count:=2

The following example moves to the next DATE field.

ActiveDocument.Range.GoTo What:=wdGoToField, Name:="Date"

The following example moves the range to the fourth line in the document.

ActiveDocument.Range.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=4

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

ActiveDocument.Range.GoTo What:=wdGoToHeading, Which:=wdGoToFirst 
ActiveDocument.Range.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1

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.

This example moves the insertion point just before the fifth endnote reference mark in the active document.

If ActiveDocument.Endnotes.Count >= 5 Then 
 ActiveDocument.Range.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.Range.GoTo(What:=wdGoToFootnote, _ 
 Which:=wdGoToFirst) 
 R1.Expand Unit:=wdCharacter 
End If

Concepts

Other resources

Show: