Jay
Fri Jul 04 16:25:04 CDT 2003
Hi Honyakuka,
Although this particular application has a simple solution, the answer to your
original question is interesting for other applications.
You can "save a copy" of the original range by using the .Duplicate property of
the Range object. This is a separate, independent range that happens to have the
same .Start and .End as the original. After you've done some operation that
moves or resizes the original, you can assign the copy back to it to restore the
location:
Sub foo()
Dim MyRange As Range, OtherRange As Range
Set MyRange = Selection.Range
Set OtherRange = MyRange.Duplicate
With MyRange
.Collapse Direction:=wdCollapseEnd
.Expand Unit:=wdCharacter
.Case = wdUpperCase
End With
Set MyRange = OtherRange
MyRange.Font.Italic = True
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site:
http://www.mvps.org/word
Doug Robbins - Word MVP wrote:
> Hi Honyakuka,
>
> If you use a wildcard replace, you should not need to repeat it.
>
> See the article ?Finding and replacing characters using wildcards? at:
>
>
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm
>
> Please respond to the newsgroups for the benefit of others who may be
> interested.
>
> Hope this helps
> Doug Robbins - Word MVP
> "HONYAKUKA" <honyakuka@aol.com> wrote in message
> news:20030703162220.00170.00000027@mb-m26.aol.com...
>> Word2000
>>
>> I would like to perform a search-replace within a selected range of
>> text (as opposed to the whole document) and perform the same search
>> repeatedly (within the original range) until the target
>> text-combination no longer exists. (Specifically, "^p^p^p" to
>> "^p^p", i.e., three contiguous paragraph marks to two.)
>>
>> I can't figure out how to retain the original selection (of course,
>> the "original" selection changes internally with each pass of the
>> search-replace). If you define a range as being the original
>> selection, that named range no longer refers to the original
>> selection (as altered) once the search-replace routine is run
>> through the first pass. I tried defining the range by setting a
>> bookmark at the beginning and one at the end of the original
>> selection, but the search-replace routine destroys the end bookmark,
>> so the orginally defined range can no longer be selected.
>>
>> Anyway, is there a foolproof way of defining the beginning and the
>> end of the original selection, so the range can be reselected and
>> the search-replace routine run till exhaustion? Thanks very much.
>>
>> Jay