View Single Post
 
Old 04-26-2022, 12:32 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
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