Document.Range Method

Word Developer Reference

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


expression.Range(Start, End)

expression   Required. A variable that represents a Document object.


Name Required/Optional Data Type Description
Start Optional Variant The starting character position.
End Optional Variant The ending character position.

Return Value


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

Visual Basic for Applications
  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.

Visual Basic for Applications
  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.

Visual Basic for Applications
  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, _
        myRange.Paragraphs.Alignment = wdAlignParagraphRight
    End If
End Sub

See Also