View Single Post
 
Old 06-02-2021, 09:46 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,384
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I don't know what 'TST_End_of_Sentence_' is about, but it seems to suggest you're running some sort of loop. Your code is also slow because of its heavy use of Selection.

With the Find/Replace operation I suggested, there'd be no looping through the content. All you'd use is:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([\(«]*>)^32"
    .Replacement.Text = "\1^s"
    .Forward = True
    .Format = False
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
You also have some strange-looking Find/Replace operations. For example:
.Text = "(*>)^32(A-Z)"
.Replacement.Text = "\1^s\2"
would replace an ordinary space before any upper-case letter with a non-breaking space. Why would you do that?

Similarly,
.Text = "([%$])"
.Replacement.Text = "^s\1"
would insert a non-breaking space before % or $, even if there's already a space there, with the potential of ending up with both a space (which may or not be a non-breaking space) followed by non-breaking space.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote