Selection.SetRange Method (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Sets the starting and ending character positions for the selection.

expression .SetRange(Start, End)

expression Required. A variable that represents a Selection object.

Parameters

Name

Required/Optional

Data Type

Description

Start

Required

Long

The starting character position of the selection.

End

Required

Long

The ending character position of the selection.

Character position values start at the beginning of the story, with the first value being 0 (zero). All characters are counted, including nonprinting characters. Hidden characters are counted even if they're not displayed.

The SetRange method redefines the starting and ending positions of an existing Selection object. This method differs from the Range method, which is used to create a Range object, given a starting and ending position.

This example selects the first 10 characters in the document.

Selection.SetRange Start:=0, End:=10

This example extends the selection to the end of the document.

Selection.SetRange Start:=Selection.Start, _ 
 End:=ActiveDocument.Content.End
Show: