Prev: wdDialogInsertCrossReference ?????????????????
Next: Extract RTF text from word without clipborad function?????
From: Paul Appleby on 22 Feb 2007 17:35 I'm using Find on a range object with a limited range to try and avoid searching more of the document than necessary as I'm repeating the operation many times. In most circumstances the result returns within the range (assuming there is a match). However when the entire selected range matches what is being searched for (which may include formatting and/or wildcards) then Word returns the next available match within the document - even though it is outside of the range being searched. It seems to me that if the properties of the range match what is being searched for then Word will not return the range as the result but return the next possible match. Can someone confirm if this is what is happening? And if so, can someone suggest a possible way to stop it from happening? Thanks Paul
From: Greg Maxey on 22 Feb 2007 19:16
Paul, Yes that is the way it works. I read an pretty good explanation of how ..Find goes about redefining a search range following each .Execute, but I can't find it now. Basically, if the found text matches the search range text "exactly" then Word loses control of the initial defined range, interprets a successful .find operation and then continues the .find procedure to IAW the .Wrap setting including the rest of the document. Here is an example of how you might work around this. Tested on a document containing this text. One, two, three. One, two, three. Sub Test() Dim oRng As Word.Range Dim oRngDup As Word.Range Dim oDoc As Document Set oDoc = ActiveDocument Set oRng = oDoc.Range oRng.Start = oDoc.Words(1).Start oRng.End = oDoc.Words(1).End Set oRngDup = oRng.Duplicate With oRng.Find .Text = oDoc.Words(1).Text While .Execute If oRng.End < oRngDup.End Then oRng.Select Else MsgBox "Text not found." End If Wend End With End Sub -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. "Paul Appleby" <PaulAppleby(a)discussions.microsoft.com> wrote in message news:CB4297AD-9F24-40CB-ACE2-9D7FF4FE7657(a)microsoft.com... > I'm using Find on a range object with a limited range to try and avoid > searching more of the document than necessary as I'm repeating the > operation > many times. > > In most circumstances the result returns within the range (assuming there > is > a match). However when the entire selected range matches what is being > searched for (which may include formatting and/or wildcards) then Word > returns the next available match within the document - even though it is > outside of the range being searched. > > It seems to me that if the properties of the range match what is being > searched for then Word will not return the range as the result but return > the > next possible match. Can someone confirm if this is what is happening? And > if > so, can someone suggest a possible way to stop it from happening? > > Thanks > > Paul |