Share via


Range Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

                          



Represents a contiguous area in a document. Each Range object is defined by a starting and ending character position. 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. However, unlike a bookmark, a Range object only exists while the procedure that defined it is running.

Note   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.

Using the Range Object

Use the Range method to return a Range object defined by the given starting and ending character positions. 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)

Use the Range property to return a Range object defined by the beginning and end of another object. The Range property applies to many objects (for example, Paragraph, Bookmark, and Cell). The following example returns a Range object that refers to the first paragraph in the active document.

Set aRange = ActiveDocument.Paragraphs(1).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)

For more information about working with Range objects, see Working with Range Objects.