Range (object)

<< Click to Display Table of Contents >>

Range (object)

Access paths:

Application à Documents à Item à Paragraphs à Item à Range

Application à ActiveDocument à Paragraphs à Item à Range

 1  Description

The Range object is a child object of the Paragraph object. It returns the start and end position of the paragraph, expressed as the number of characters from the top of the document.

 2  Access to the object

For each Paragraph object there is exactly one Range object. This Range object can be accessed solely through the object pointer Range in the associated Paragraph object:

' Display the end position of the first paragraph in the active document

MsgBox tm.ActiveDocument.Paragraphs.Item(1).Range.End

 3  Properties, objects, collections and methods

Properties:

Start R/O

End R/O

 

Objects:

Application Application

Parent Paragraph

Start (property, R/O)

Data type: Long

Returns the start position of the paragraph, expressed as the number of character from the top of the document.

End (property, R/O)

Data type: Long

Returns the end position of the paragraph, expressed as the number of characters from the top of the document.

An example for Start and End:

If the first paragraph of a document consists of the text "The first paragraph", the following applies:

tm.ActiveDocument.Paragraphs.Item(1).Range.Start returns the value 0 ("the zeroth character from the beginning of the document").

tm.ActiveDocument.Paragraphs.Item(1).Range.End returns 20.

You can use these values to select a paragraph or a part of it:

' Select the first two characters of the first paragraph

tm.ActiveDocument.Selection.SetRange 0, 1

 

' Select the whole paragraph

With tm.ActiveDocument

 .Selection.SetRange .Paragraphs(1).Range.Start, .Paragraphs(1).Range.End

End With

You can select the first four paragraphs of a document as follows:

With tm.ActiveDocument

 .Selection.SetRange .Paragraphs(1).Range.Start, .Paragraphs(4).Range.End

End With

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. an object of the type Paragraphs.