Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-07-2016, 09:30 AM
Robert K S Robert K S is offline Workarounds for the find "dynamic" range bug in VBA? Windows 7 64bit Workarounds for the find "dynamic" range bug in VBA? Office 2007
Novice
Workarounds for the find "dynamic" range bug in VBA?
 
Join Date: Jul 2016
Location: Cleveland, Ohio
Posts: 10
Robert K S is on a distinguished road
Default Workarounds for the find "dynamic" range bug in VBA?

I have a script in which I want to do a bunch of "find-and-replace"s on a range defined by a selection in Microsoft Word. Something like in the code snippet below. The problem is, after the first find & replace the selection range changes and the new second find & replace call operates on portions outside the user-defined selection made before running the script. (Discussion of this bug here.)

Are there any workarounds for this issue? For example, is there any way to store the selection range endpoint values, update them with changed values (since the effective range may have changed with any replacements made), and then use the changed range values as the new find & replace range?



Code:
With Selection.Range.Find ' Replace "OLD" with "NEWTHING"
    .MatchCase = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = "OLD"
    .Replacement.Text = "NEWTHING"
    .Execute Replace:=wdReplaceAll
End With
With Selection.Range.Find ' Replace "REPLACEME" with "THEREPLACEMENT"
    .MatchCase = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = "REPLACEME"
    .Replacement.Text = "THEREPLACEMENT"
    .Execute Replace:=wdReplaceAll
End With
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Workarounds for the find "dynamic" range bug in VBA? "Dynamic" pie chars? Markstar Excel 3 09-16-2015 10:02 AM
Workarounds for the find "dynamic" range bug in VBA? I searched for "fatta" but Word can't find "Fatta" or "FATTA" why? Jamal NUMAN Word 1 07-14-2011 02:05 AM
Workarounds for the find "dynamic" range bug in VBA? How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM
Workarounds for the find "dynamic" range bug in VBA? Outlook Web Access: How to load the "Microsoft Dynamic Html Editing Control" Add-On? tomtom67 Outlook 1 08-31-2009 12:23 AM
Workarounds for the find "dynamic" range bug in VBA? Mysterious "Subscript out of range" error rnstewart Excel 4 12-29-2005 01:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:11 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