Selection 方法 (Word)Selection.Move method (Word)

将指定的所选内容折叠到其起始位置或结束位置,然后将折叠的对象移动指定的单位数。Collapses the specified selection to its start or end position and then moves the collapsed object by the specified number of units. 此方法返回一个Long类型的值, 该值代表所选内容移动的单位数, 如果移动不成功, 则返回 0 (零)。This method returns a Long value that represents the number of units by which the selection was moved, or it returns 0 (zero) if the move was unsuccessful.

语法Syntax

expressionexpression. Move( _Unit_ , _Count_ )

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
UnitUnit 可选Optional WdUnitsWdUnits 移动结束字符位置时所基于的单位。The unit by which to move the ending character position.
CountCount 可选Optional VariantVariant 指定的区域或所选内容的移动的单位数。The number of units by which the specified range or selection is to be moved. 如果 Count 是一个正数,对象折叠到其结束位置,并在文档中向后移动指定的单位数。If Count is a positive number, the object is collapsed to its end position and moved backward in the document by the specified number of units. 如果 Count 是一个负数,对象折叠到其起始位置,并向前移动指定的单位数。If Count is a negative number, the object is collapsed to its start position and moved forward by the specified number of units. 默认值为 1。The default value is 1. 您还可以在使用Move方法之前使用collapse方法控制折叠方向。You can also control the collapse direction by using the Collapse method before using the Move method. 如果该区域或所选内容位于一个单位的中间,或者不能折叠,将其移动到的开头或结尾的部门计为移动它一个完整的单元。If the range or selection is in the middle of a unit or isn't collapsed, moving it to the beginning or end of the unit counts as moving it one full unit.

返回值Return value

LongLong

注解Remarks

折叠的范围或所选内容的开始和结束位置相同。The start and end positions of a collapsed range or selection are equal.

将 Move方法应用于区域不会重新排列文档中的文本。Applying the Move method to a range doesn't rearrange text in the document. 相反,它重新定义该区域,以引用文档中的新位置。Instead, it redefines the range to refer to a new location in the document.

如果将Move方法应用于range对象变量以外的任何区域 (例如, Selection.Paragraphs(3).Range.Move), 则该方法将不起作用。If you apply the Move method to any range other than a Range object variable (for example, Selection.Paragraphs(3).Range.Move), the method has no effect.

移动选择对象会折叠选定内容, 并在文档中向前或向后移动插入点。Moving a Selection object collapses the selection and moves the insertion point either forward or backward in the document.

示例Example

以下示例将所选内容向右移动两个单词,并将插入点放在第二个单词的尾部空格后。This example moves the selection two words to the right and positions the insertion point after the second word's trailing space. 如果移动失败,则会显示一个消息框,表明所选内容位于文档的末尾。If the move is unsuccessful, a message box indicates that the selection is at the end of the document.

If Selection.StoryType = wdMainTextStory Then 
 wUnits = Selection.Move(Unit:=wdWord, Count:=2) 
 If wUnits < 2 Then _ 
 MsgBox "Selection is at the end of the document" 
End If

以下示例将所选内容在表格中向前移动三个单元格。This example moves the selection forward three cells in the table.

If Selection.Information(wdWithInTable) = True Then 
 Selection.Move Unit:=wdCell, Count:=3 
End If

另请参阅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.