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

将区域或选定内容的结束字符位置移动或扩展至最近的一个指定文本单元末尾。Moves or extends the ending character position of a range or selection to the end of the nearest specified text unit.


expressionexpression. EndOf( _Unit_ , _Extend_ )

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


名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
UnitUnit 可选Optional VariantVariant 结束字符位置移至的单元。The unit by which to move the ending character position. WdUnits.
ExtendExtend 可选Optional VariantVariant 可以是WdMovementType常量之一。Can be either of the WdMovementType constants. 如果 wdMove ,则区域和选定内容对象的结尾都移至指定单位的末尾。If wdMove, both ends of the range or selection object are moved to the end of the specified unit. 如果使用了 wdExtend ,则该区域或所选内容的末尾被扩展到指定单位的末尾。If wdExtend is used, the end of the range or selection is extended to the end of the specified unit. 默认值为 wdMoveThe default value is wdMove.


本方法返回该区域或所选内容所移动或扩展的字符位置数(移动方向为向前)。This method returns a value that indicates the number of character positions the range or selection was moved or extended (movement is forward in the document).

如果区域或选定内容的开始和结束位置都已在指定单位的末尾,则该方法不移动或扩展此区域或选定内容。If the both the starting and ending positions for the range or selection are already at the end of the specified unit, this method doesn't move or extend the range or selection. 例如, 如果所选内容位于某个单词的末尾和尾部空格, 则以下指令不会更改所选内容 ( _char_等于 0 (零))。For example, if the selection is at the end of a word and the trailing space, the following instruction doesn't change the selection ( char equals 0 (zero)).

char = Selection.EndOf(Unit:=wdWord, Extend:=wdMove)


本示例将选定内容扩展至段落末尾。This example extends the selection to the end of the paragraph.

charmoved = Selection.EndOf(Unit:=wdParagraph, Extend:=wdExtend) 
If charmoved = 0 Then MsgBox "Selection unchanged"

本例将字符串 myRange 移动到选定内容的第一个单词的末尾。This example moves myRange to the end of the first word in the selection (after the trailing space).

Set myRange = Selection.Characters(1) 
myRange.EndOf Unit:=wdWord, Extend:=wdMove

本示例先添加一个表格,选择第二行第一个单元,再将选定内容扩展到列末。This example adds a table, selects the first cell in row two, and then extends the selection to the end of the column.

Set myRange = ActiveDocument.Range(0, 0) 
Set myTable = ActiveDocument.Tables.Add(Range:=myRange, _ 
 NumRows:=5, NumColumns:=3) 
myTable.Cell(2, 1).Select 
Selection.EndOf Unit:=wdColumn, Extend:=wdExtend

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