View Single Post
 
Old 03-26-2023, 08:08 AM
syl3786 syl3786 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Unhappy Add spaces between sentences

Hi community,

I have edited the macro based on Gregory K. Maxey's TwoSpacesAfterSentence (The Anchorage - 404 Redirect

Code:
Sub TwoSpacesAfterSentence()

Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
  
    .ClearFormatting
    .MatchWildcards = True
    
    .Text = "(*{2})([.\!\?])([A-Z])"
    .Replacement.Text = "\1\2  \3" 'Two spaces between 2 and \
    .Execute Replace:=wdReplaceAll
    
    .Text = "(*{2})([.\!\?]) ([A-Z])"
    .Replacement.Text = "\1\2  \3" 'Two spaces between 2 and \
    .Execute Replace:=wdReplaceAll
    
    .Text = "([.\!\?]) {3,}([A-Z])"
    .Replacement.Text = "\1  \2"
    .Execute Replace:=wdReplaceAll
    
    'This should prevent most cases of improper double spacing
    'in names (e.g., F. Lee Bailey, George W. Bush, etc.)
    .Text = "([!A-Z][A-Z].)  ([A-Z])" 'Two spaces between ) and (
    .Replacement.Text = "\1 \2"
    .Execute Replace:=wdReplaceAll
    
  End With
lbl_exit:
  Exit Sub
End Sub
It runs well in a 10 pages documents, with the first word of the sentence not in bold type. However, when it runs in a documents more than 100 pages, and the first word of the first sentence in the paragraph, the Microsoft Word will be collapsed.

I tried to add "Application.ScreenUpdating = False" at the very first begining of the code and it runs a little bit faster. However, it still cannot be ran successfully in a more than 100 pages documents.

How to solve this issue? Your help will be greatly appreciated!
Reply With Quote