Range 对象 (Word)Range object (Word)

表示文档中的一个连续区域。Represents a contiguous area in a document. 每个 Range 对象由一个起始字符位置和一个终止字符位置定义。Each Range object is defined by a starting and ending character position.

备注Remarks

与书签在文档中的使用方法类似,Range 对象在 Visual Basic 过程中用来标识文档的特定部分。Similar to the way bookmarks are used in a document, Range objects are used in Visual Basic procedures to identify specific portions of a document. 但与书签不同的是,Range对象只在定义该对象的过程运行时才存在。However, unlike a bookmark, a Range object only exists while the procedure that defined it is running. Range 对象不受选定内容影响。Range objects are independent of the selection. 这就是说,你可以定义区域并对其进行操作,无需更改选定内容。That is, you can define and manipulate a range without changing the selection. 此外,你还可以在文档中定义多个区域,但每个窗格只能具有一个选定内容。You can also define multiple ranges in a document, while there can be only one selection per pane.

使用Range方法返回一个Range对象, 该对象由给定的起始和结束字符位置定义。Use the Range method to return a Range object defined by the given starting and ending character positions. 以下示例将返回引用活动文档中的前 10 个字符的 Range 对象。The following example returns a Range object that refers to the first 10 characters in the active document.

Set myRange = ActiveDocument.Range(Start:=0, End:=10)

使用Range属性可返回一个Range对象, 该对象由另一个对象的开头和结尾定义。Use the Range property to return a Range object defined by the beginning and end of another object. Range 属性适用于多种对象(例如 ParagraphBookmarkCell)。The Range property applies to many objects (for example, Paragraph, Bookmark, and Cell). 以下示例返回引用活动文档中第一段的 Range 对象。The following example returns a Range object that refers to the first paragraph in the active document.

Set aRange = ActiveDocument.Paragraphs(1).Range

下面的示例返回一个Range对象, 该对象引用活动文档中的第二到第四个段落。The following example returns a Range object that refers to the second through fourth paragraphs in the active document.

Set aRange = ActiveDocument.Range( _ 
 Start:=ActiveDocument.Paragraphs(2).Range.Start, _ 
 End:=ActiveDocument.Paragraphs(4).Range.End)

有关处理range对象的详细信息, 请参阅处理 range 对象For more information about working with Range objects, see Working with Range objects.

方法Methods

属性Properties

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