Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2023, 08:08 AM
syl3786 syl3786 is offline Add spaces between sentences Windows 10 Add spaces between sentences Office 2019
Advanced Beginner
Add spaces between sentences
 
Join Date: Jan 2023
Posts: 68
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add spaces between sentences VBA semi colon at end of sentences Shelley Lou Word VBA 5 05-28-2021 02:35 AM
Alignment of sentences aditya@office Excel 11 09-24-2019 06:22 AM
Add spaces between sentences remove dependency between sentences Baby_1 Word 3 07-18-2017 12:39 AM
Consolidating Sentences into One Paragraph ctsolar Word 4 12-16-2013 04:50 PM
Add spaces between sentences Postformatting spaces between sentences using auto correct? Chunk Word 4 05-12-2011 06:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft