选择. GoTo 方法 (Word)Selection.GoTo method (Word)

将插入点移至紧靠指定项之前的字符位置, 并返回一个**Range** 对象 ( wdGoToGrammaticalErrorwdGoToProofreadingErrorwdGoToSpellingError除外)常量)。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).

语法Syntax

expressionexpression. GoTo( _What_ , _Which_ , _Count_ , _Name_ )

expression:必需。expression Required. 表示 Selection 对象的变量。A variable that represents a Selection object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
WhatWhat 可选Optional VariantVariant 将范围或选中范围移到的项的类型。The kind of item to which the range or selection is moved. 可取值为 WdGoToItem 常量之一。Can be one of the WdGoToItem constants.
WhichWhich 可选Optional VariantVariant 将范围或选中范围移到的项。The item to which the range or selection is moved. 可取值为 WdGoToDirection 常量之一。Can be one of the WdGoToDirection constants.
CountCount 可选Optional VariantVariant 在文档中的项的数目。The number of the item in the document. 默认值为 1。The default value is 1. 仅正值有效。Only positive values are valid. 若要指定范围或选中范围前的项,请使用 wdGoToPrevious 作为 Which 参数,并指定 Count 值。To specify an item that precedes the range or selection, use wdGoToPrevious as the Which argument and specify a Count value.
NameName 可选Optional VariantVariant 如果 What 参数为wdGoToBookmarkwdGoToCommentwdGoToFieldwdGoToObject, 则此参数指定一个名称。If the What argument is wdGoToBookmark, wdGoToComment, wdGoToField, or wdGoToObject, this argument specifies a name.

返回值Return value

现在选中的 RangeThe Range that is now selected.

注解Remarks

GoTo 方法与 wdGoToGrammaticalErrorwdGoToProofreadingErrorwdGoToSpellingError 常量一起使用时,返回的 Range 对象中包括所有含语法或拼写错误的文本。When you use the GoTo method with the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant, the Range object that is returned includes any grammar error text or spelling error text.

示例Examples

下面的示例在功能上是等效的;它们都将选中范围移到文档中的第一个标题。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

以下示例将所选内容移至文档中的第四行。The following example moves the selection to the fourth line in the document.

Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=4

以下示例将所选内容向上移动两行。The following example moves the selection up two lines.

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

下面的示例展示了如何移到下一个 DATE 字段。The following example moves to the next DATE field.

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

下面的示例展示了如何将选定范围移到下一个表格中的第一个单元格。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 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

另请参阅See also

Selection 对象Selection Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.