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

将选定内容移动或扩展到指定单位的末尾。Moves or extends the selection to the end of the specified unit.


expressionexpression. EndKey( _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 the selection is to be moved or extended. 可以是**** 常量。Can be a WdUnits constant. 默认值是 wdLineThe default value is wdLine.
ExtendExtend 可选Optional VariantVariant 指定移动所选内容的方式。Specifies the way the selection is moved. 可以是任何**WdMovementType** 常量。Can be any WdMovementType constant. 如果该参数值为 wdMove,则所选内容折叠到一个插入点中并移至指定单位的末尾。If the value of this argument is wdMove, the selection is collapsed to an insertion point and moved to the end of the specified unit. 如果该参数值为 wdExtend,则所选内容的末尾扩展到指定单位的末尾。If it is wdExtend, the end of the selection is extended to the end of the specified unit. 默认值为 wdMoveThe default value is wdMove.


此方法返回一个整数, 表示所选内容或活动端实际移动的字符数, 如果移动不成功, 则返回 0 (零)。This method returns an integer that indicates the number of characters the selection or active end was actually moved, or it returns 0 (zero) if the move was unsuccessful. 此方法对应于 END 键的功能。This method corresponds to functionality of the END key.


本示例将选定内容移动到当前行尾,然后把移动的字符数赋给 pos 变量。This example moves the selection to the end of the current line and assigns the number of characters moved to the pos variable.

pos = Selection.EndKey(Unit:=wdLine, Extend:=wdMove)

本示例将所选内容移至当前表格列的开始,然后将所选内容扩展至列的末尾。This example moves the selection to the beginning of the current table column and then extends the selection to the end of the column.

If Selection.Information(wdWithInTable) = True Then 
 Selection.HomeKey Unit:=wdColumn, Extend:=wdMove 
 Selection.EndKey Unit:=wdColumn, Extend:=wdExtend 
End If

本示例将所选内容移至当前文字部分的末尾。This example moves the selection to the end of the current story. 如果所选内容位于文档正文部分,则本示例将所选内容移至文档的末尾。If the selection is in the main text story, the example moves the selection to the end of the document.

Selection.EndKey Unit:=wdStory, Extend:=wdMove

另请参阅See also

支持和反馈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.