Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-25-2018, 07:09 AM
mark99k's Avatar
mark99k mark99k is offline VBA Find inexplicably aborts & goes to top Windows 7 32bit VBA Find inexplicably aborts & goes to top Office 2010 32bit
Novice
VBA Find inexplicably aborts & goes to top
 
Join Date: Oct 2012
Location: California USA
Posts: 20
mark99k is on a distinguished road
Default VBA Find inexplicably aborts & goes to top

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
What happens: it stops looking, after finding several matches, sends the cursor to the top of the file, then flutters as if stuck in a loop, then hangs. No error message or other clues.

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
Reply With Quote
 

Tags
vba find and replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
find IP in range / find number between numbers gn28 Excel 4 06-14-2015 03:46 PM
VBA Find inexplicably aborts & goes to top Find where find text contains a double quote norgro Word VBA 1 01-23-2015 10:58 PM
VBA Find inexplicably aborts & goes to top Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
VBA Find inexplicably aborts & goes to top Macro that can find phrase and then find another and copy jperez84 Word VBA 10 09-19-2012 04:48 PM
VBA Find inexplicably aborts & goes to top Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft