Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 04-26-2022, 12:32 AM
Guessed's Avatar
Guessed Guessed is offline replacing_within_range Windows 10 replacing_within_range Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There is also the potential that the rng is collapsing after the first pass. In my experience, when you use rng.Find the rng collapses to the found instances so a second pass may not include the rng you thought you were looking for.

To avoid this you could redefine the rng before each pass.
Code:
Sub nnewreplace()
    Dim e(), f()
    e = Array(" ", " ", Chr(160), Chr(9), "\(([a-z]{1,})\)")
    f = Array("", "", "", "", "\1.")
    Dim i As Integer, rng As Range
    
    For i = LBound(e) To UBound(e)
        Set rng = Selection.Range
        With rng.Find
            .ClearFormatting
            .MatchWildcards = True
            .Text = e(i)
            .Replacement.Text = f(i)
            .Wrap = wdFindStop
            .Execute Replace:=wdReplaceAll
        End With
    Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Other Forums: Access Forums

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