Use
Do While .Execute(findText:="\/[0-9]{3,}", MatchWildCards:=True,
Forward:=True, Wrap:=wdFindStop)
For an explanation, see the article "Finding and replacing characters
using
wildcards" at:
http://www.word.mvps.org/FAQs/General/UsingWildcards.htm
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
Doug,
Thanks sooo much for that piece of code. Its so much faster than the
way I was doing it, on this thin client at least (which is what the
majority of the users will be on).
One additional query if I might...
Without repeating the following line over and over (essentially copy/
past spamming the code)
Do While .Execute(findText:="/6346", Forward:=True, Wrap:=wdFindStop)
=
How can I get the
findText:=
to allow multiple strings. Like /6346, /137, and /138? I have about 30
strings I want to color red, another 10 or so blue, and the rest
green. But every time I try and add a second string it debugs on me.
Again, thanks for the help so far!
On Aug 9, 3:50 pm, "Doug Robbins - Word MVP" <
[email protected]>
wrote:
You need to use the Wrap: attribute
Dim myrange as Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="/6346", Forward:=True,
Wrap:=wdFindStop)
=
True
Set myrange = Selection.Bookmarks("\line").Range
With myrange.Font
.Bold = wdToggle
.Color = wdColorRed
End With
Selection.Collapse wdCollapseEnd
Loop
End With
Note, that if you change the text to Bold, it may flow over to the
next
line.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
On Aug 9, 1:46 pm, (e-mail address removed) wrote:
I'm trying to execute this macro on hourly raw data dumps and I'm
finding that when it gets to the end of the document it goes back
up
it and seems to be undoing the bold/font color changes. Am I
missing
something that forces the macro to stop at the end of the
document...
I assumed it would stop when it found no more changes at the end...
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="/6346") = True
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Color = wdColorRed
Selection.EndKey Unit:=wdLine
Loop
End With
End Sub
Thanks in advance.
Actually, this seems to be working for me:
Selection.HomeKey unit:=wdStory
With Selection.Find
.ClearFormatting
.Text = "/6346"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Color = wdColorRed
Selection.EndKey unit:=wdLine
Loop
End With
End Sub
Although Word is now constantly popping up a Debugger box asking me
to
Continue, Stop, Debug, etc... but thats happening on all my Macros
now.
Either way, anyone think the code could be better/cleaner? Input it
still very welcome.