Hi =?Utf-8?B?Sm9hbm5l?=,
> I assigned a variable oRnge=ActiveDocument.Range and then performed a search
> for a string of numbers. Once the string is found, the text is manipulated
[quoted text clipped - 3 lines]
> through the document when the value of oRnge has changed? I'm just curious
> as to how this works.
My preference is to collapse the found range to its end-point (rng.Collapse
wdCollapseEnd), then extend the End property to the End property of the
document's range (rng.End = doc.Range.End).
Note, however, that if your document contains tables, and the found range might
be in a table cell, you MAY have to work differently as extending a range beyond
the cell will include the entire table in the range. This is fine, as long as
you've altered the text in the found range so that it won't be found again.
Otherwise, you end up in a loop.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Klaus Linke - 31 Mar 2005 02:12 GMT
And another option would be to start with an empty Range at the top, search downwards, and stop if nothing more is found...
Something like
Dim myRange As Range
Set myRange = ActiveDocument.Range(0, 0)
With myRange.Find
.Text = "a"
.Wrap = wdFindStop
.Forward = True
' other stuff as needed
End With
Do While myRange.Find.Execute
' myRange.Select
' or do whatever
myRange.Collapse(wdCollapseEnd)
Loop
Collapsing myRange to its end-point is necessary if you change the text of myRange, so Word doesn't look for your Find text in myRange, causing it to loop endlessly (if it finds it) or stopping prematurely (if it doesn't).
Regards,
Klaus
"Cindy M -WordMVP-" <C.Meister-C@hispeed.ch> wrote:
> Hi =?Utf-8?B?Sm9hbm5l?=,
>
[quoted text clipped - 23 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)