Document.Range Method (Word)

Returns a Range object by using the specified starting and ending character positions.

Syntax

expression .Range(Start, End)

expression Required. A variable that represents a Document object.

Parameters

Name

Required/Optional

Data Type

Description

Start

Optional

Variant

The starting character position.

End

Optional

Variant

The ending character position.

Return Value

Range

Example

This example applies bold formatting to the first 10 characters in the active document.

Sub DocumentRange() 
 ActiveDocument.Range(Start:=0, End:=10).Bold = True 
End Sub

This example creates a range that starts at the beginning of the active document and ends at the cursor position, and then it changes all characters within that range to uppercase.

Sub DocumentRange2() 
 Dim r As Range 
 Set r = ActiveDocument.Range(Start:=0, End:=Selection.End) 
 r.Case = wdUpperCase 
End Sub

This example creates and sets the variable myRange to paragraphs three through six in the active document, and then it right-aligns the paragraphs in the range.

Sub DocumentRange3() 
 Dim aDoc As Document 
 Dim myRange As Range 
 Set aDoc = ActiveDocument 
 If aDoc.Paragraphs.Count >= 6 Then 
 Set myRange = aDoc.Range(aDoc.Paragraphs(2).Range.Start, _ 
 aDoc.Paragraphs(4).Range.End) 
 myRange.Paragraphs.Alignment = wdAlignParagraphRight 
 End If 
End Sub

See Also

Concepts

Document Object

Document Object Members