Hello,
The only text in my document is :
<ABCDE><FGHIJK>lmno<PQRSTU><VWXYZ>
The purpose of this function is to get only the XML tags of the
selection.
If I manually select (highlight) <FGHIJK>mno<PQRSTU> and run this
code, I get <FGHIJK><PQRSTU><VWXYZ> when I was only expecting
<FGHIJK><PQRSTU>.
What's wrong with this??? It seems that the wdFindStop doesn't do its
job and the function searches to the end of the document (I tried with
much longer lines in the document: same problem)
Set MyRange = Selection.Range
With MyRange.Find
.Text = "\<*\>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While MyRange.Find.Execute
sXmlTagOnly = sXmlTagOnly & MyRange.Text
Loop
Thank you for your help!
Frédéric Laurent
Jay Freedman - 26 Nov 2004 04:35 GMT
Hi Frédéric,
The problem you're running into is that every time you call .Execute
and it returns True, it has redefined myRange to cover the found text.
For example, after the first call, myRange covers <FGHIJK>. This means
that the next call will start searching from the end of that area.
Since myRange no longer extends beyond that first area, the trigger
point for .Wrap is the end of the document, not the end of the
original range.
To fix this, change the Do While statement to
Do While myRange.Find.Execute And _
myRange.InRange(Selection.Range)
When the found text lies outside the Selection, the loop will stop.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
http://www.gmayor.com/replace_using_wildcards.htm
>Hello,
>
[quoted text clipped - 32 lines]
>
>Frédéric Laurent
Jean-Guy Marcil - 26 Nov 2004 05:09 GMT
Fr?d?ric Laurent was telling us:
Fr?d?ric Laurent nous racontait que :
> Hello,
>
[quoted text clipped - 11 lines]
> job and the function searches to the end of the document (I tried with
> much longer lines in the document: same problem)
I was going to suggest something similar to Jay's approach. Here it is
anyway, it might help you later with a different problem. It is based on the
Duplicate property:
'_______________________________________
Dim MyRange As Range
Set MyRange = Selection.Range
With MyRange.Duplicate
With .Find
.Text = "\<*\>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While .Find.Execute And .InRange(MyRange)
sXmlTagOnly = sXmlTagOnly & .Text
Loop
End With
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Fr?d?ric Laurent - 26 Nov 2004 19:39 GMT
Thank you very much to both of you !
Jean-Guy, I appreciate you introduced this new (to me at least) method
.Duplicate. It will be usefull to do other things!
FL
> Fr?d?ric Laurent was telling us:
> Fr?d?ric Laurent nous racontait que :
[quoted text clipped - 42 lines]
> End With
> '_______________________________________
Jean-Guy Marcil - 26 Nov 2004 20:05 GMT
Fr?d?ric Laurent was telling us:
Fr?d?ric Laurent nous racontait que :
> Thank you very much to both of you !
> Jean-Guy, I appreciate you introduced this new (to me at least) method
> .Duplicate. It will be usefull to do other things!
Glad to have been able to help!

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org