Assigning Ranges
Word Developer Reference |
There are several ways to assign an existing Range object to a variable. This topic explains the results of two different techniques. In the following examples, the
|
and
|
variables refer to Range objects. For example, the following instructions assign the first and second words in the active document to the
|
and
|
variables.
|
Setting a Range object variable equal to another Range object variable
This following instruction assigns a range variable named
|
to represent to the same location as
|
.
|
You now have two variables that represent to the same range. When you manipulate the start or endpoint or the text of
|
, it affects
|
and vice versa.
Note that the following instruction is the same as
|
. This instruction assigns the default property of
|
, which is the Text property, to the default property of
|
. It doesn't change what the objects actually refer to.
|
The ranges (
|
and
|
) have the same contents, but they may point to different locations in the document or even different documents.
Using the Duplicate property
The following instruction creates a new duplicated Range object,
|
, which has the same start and endpoints and text as
|
.
|
If you change the start or endpoint of
|
, it doesn't affect
|
and vice versa. Because these two ranges point to the same location in the document, changing the text in one range affects the text in the other range.