![]() |
#1
|
||||
|
||||
![]()
What quirk in a document could cause this code to stop looking for more matches, (when there definitely are more):
Code:
Sub MarkParenthesizedItalicsNoProofing() Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find .Text = "\([A-Z][a-z.]@[!\)]@\)" .MatchWildcards = True .Wrap = False Do While .Execute Selection.MoveStart wdCharacter, 1 Selection.MoveEnd wdCharacter, -1 If Selection.Range.Italic = True Then Selection.Range.NoProofing = True End If Selection.Collapse wdCollapseEnd Loop End With End Sub It only happens on certain files so I surmise it's something about those files and not the code, but for the life of me I can't figure out what's different about them. They vary widely but none are especially long or complex or old or mishandled. The point where the code stops looking varies, but if I copy & paste the first bunch of (successful) matches a dozen times, the macro will find *all* of those, then still freak out on one of the later ones. So the number of iterations seems to be irrelevant. I've tried progressively more desperate simplifications, even not using Do While .Execute at all -- just a regular Find, then if .Found is True, collapse the selection and go to a label above the Find block. Even that variant crazily stops at a random point, goes to the top of the file and hangs. I know this doesn't present well. I also know the Find feature can be quirky. Still, seems like this shouldn't happen. Any ideas? Using Word 2016, Windows 10 Pro. Mark |
Tags |
vba find and replace |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
find IP in range / find number between numbers | gn28 | Excel | 4 | 06-14-2015 03:46 PM |
![]() |
norgro | Word VBA | 1 | 01-23-2015 10:58 PM |
![]() |
Hoxton118 | Word VBA | 7 | 06-10-2014 05:05 AM |
![]() |
jperez84 | Word VBA | 10 | 09-19-2012 04:48 PM |
![]() |
paulkaye | Word | 4 | 12-06-2011 11:05 PM |