Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[0-9]*[?., ]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
MyNumber = Selection.Text
...
Selection.MoveStartUntil Cset:="!?." & Chr(10) & Chr(11) &
Chr(12) & Chr(13), Count:=wdBackward
...
Wend
The MoveStartUntil hangs forever if there is a comment in the text the
Selection is expanded backward to. Anybody have any ideas why this
happens or how I could fix it?
Thanks much.
Garrett
How are you going with this?
Can you post a sample (text only) of the doc you are searching?
I made up some text to run your code over.
he code as it stands running on my text sample will get stuck ina loop
anyway. The reason is that the Selection.MoveStartUntil method you
are using moves the selection backwards. The net effect is that the
next iteration of the find will hit the very same target you just
moved back from.
Hope this helps.
Cheers
TonyS.
Regards,
Klaus
Tony,
I left out a step before the MoveStartUntil:
SelectEnd = Selection.End
And a step after MoveStartUntil where I advance the selection past the
end of the previous selection:
Selection.MoveRight Unit:=wdCharacter, Count:=SelectEnd -
Selection.End, Extend:=wdMove
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
Klaus,
Thanks for the Chr(5) info. Do you have any ideas about how to skip
over the comment data? Just adding Chr(5) to CSet would make me stop
there and potentially miss words before the comment that I want to
process. Is there a Chr(5) at the beginning of the comment as well?
I suppose I could get off my butt and take a look myself...
Below is a sample of the text I am searching. You need to add a Word
comment between the article "the" and the number "100" on the word
"test" to reproduce the problem. So, I do not want to stop at the
comment char because then I would miss "This is the test" when the
selection on "100" is expanded back to the previous period at the end
of the first sentence.
This is a test. This is the test 100.
Thanks again guys.
I think Tony was on the money... The comments may not have much to do
with
the problem.
If you single-step through your code (F8 in the VBA editor), it
shouldn't be
too hard to find where the selection doesn't move as you expect?
At least I can't see anything in your code that would make it hang on
a
comment.
The comment marker (ASCII 5) might be a problem in the text you
retrieve,
and you may want to remove it:
myNumber = Replace(Selection.Text, ChrW(5), "")
Only BTW: There isn't anything to mark the start of the commented
text...
You'd need to look at myComment.Scope to tell the range that's
highlighted
("scoped").
Regards,
Klaus
"G-Money" <garrett....@gmail.com> schrieb: