Make a copy of a Word Range object

  • Thread starter Thread starter Jeffrey Bradshaw
  • Start date Start date
J

Jeffrey Bradshaw

Is there any way to make a copy of a word.range object? I have a range in a
document and I need to monkey around with it but I don't want to change the
original in the document. I've tried Duplicate() and assigning it to a new
variable. But if I change the stuff in the new variable, it changes the
original also.

So what I need is a new copy of the variable - not pointing to the same
thing.

TIA - Jeffrey
 
What exactly do you mean by "changing stuff"? As I understand it,
Duplicatae() returns a clone of the original range object.

If you modify the the text or formatting properties of the original range,
however, the duplicated range will also show the same change -- because the
change to the first range is actually changing the underlying Word document.
For example in this air code,

Dim FirstRange as Word.Range = Word.Selection.Range
Dim SecondRange as Word.Range = FirstRange.Duplicate()
FirstRange.Text = "New text"

the text of SecondRange will also be changed to "New text" because the
underlying Word document has changed. The two range objects are merely
"pointers" (of sorts) for the content in the Word document itself.

However, if you make a change to a range that doesn't modify the document,
it should only affect that particular range object. For example, if you
have the line "FirstRange.Length = 0" it shouldn't change the length of
SecondRange.

Is this your issue, or is there something else? Perhaps you could post a
sample of code that illustrates your problem.
 
Back
Top