所选的 SetRange 方法 (Word)Selection.SetRange method (Word)

设置所选内容的起始字符和结束字符的位置。Sets the starting and ending character positions for the selection.

语法Syntax

expressionexpression. SetRange( _Start_ , _End_ )

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
StartStart 必需Required LongLong 所选内容的起始字符位置。The starting character position of the selection.
EndEnd 必需Required LongLong 所选内容的结束字符位置。The ending character position of the selection.

备注Remarks

字符位置值从文章的开头开始, 第一个值为 0 (零)。Character position values start at the beginning of the story, with the first value being 0 (zero). 将计算所有字符,包括非打印字符。All characters are counted, including nonprinting characters. 隐藏字符即便未显示也计算在内。Hidden characters are counted even if they're not displayed.

SetRange方法重新定义现有Selection对象的起始和结束位置。The SetRange method redefines the starting and ending positions of an existing Selection object. 此方法不同于 Range 方法,后者用于创建一个 Range 对象,给出起始和结束位置。This method differs from the Range method, which is used to create a Range object, given a starting and ending position.

示例Example

以下示例选择文档中的前 10 个字符。This example selects the first 10 characters in the document.

Selection.SetRange Start:=0, End:=10

以下示例将所选内容扩展至文档末尾。This example extends the selection to the end of the document.

Selection.SetRange Start:=Selection.Start, _ 
 End:=ActiveDocument.Content.End

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