Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2020, 06:41 AM
jarjarb jarjarb is offline Macro for fixing abnormally formatted paragraph line breaks Windows 10 Macro for fixing abnormally formatted paragraph line breaks Office 2019
Novice
Macro for fixing abnormally formatted paragraph line breaks
 
Join Date: Oct 2020
Posts: 1
jarjarb is on a distinguished road
Default Macro for fixing abnormally formatted paragraph line breaks

Hey all,

I was wondering if someone can help me with an issue. I have been using a Macro to format incorrectly formatted line breaks. For example:

Hey my name


is Jarjarb52

to

Hey my name is Jarjarb52

However, I was wondering if this Macro can be changed in a couple ways:
1) If there is a capital letter, a quote sign ("), or a number (1,2,3,etc), then it should not remove the line break
2) If there is a double line break, it should not get rid of it. Ex:
"Hey my name is Jarjarb52.

Today is a sunny day"
In this case, it should leave it as is.

Can anyone tell me how to edit the following macro to do these two things?

Code:
Sub CleanUpPastedText()
    Application.ScreenUpdating = False
    With Selection.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchAllWordForms = False
      .MatchSoundsLike = False
      .MatchWildcards = True
      'Eliminate spaces & tabs before paragraph breaks.
      .Text = "[ ^s^t]{1,}^13"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
      'Replace single paragraph breaks with a space
      .Text = "([!^13])([^13])([!^13])"
      .Replacement.Text = "\1 \3"
      'Replace all double spaces with single spaces
      .Execute Replace:=wdReplaceAll
      .Text = "[ ]{2,}"
      .Replacement.Text = " "
      'Delete hypens in hyphenated text formerly split across lines
      .Execute Replace:=wdReplaceAll
      .Text = "([a-z])-[ ]{1,}([a-z])"
      .Replacement.Text = "\1\2"
      .Execute Replace:=wdReplaceAll
      'Limit paragraph breaks to one per 'real' paragraph.
      .Text = "[^13]{1,}"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
    End With
    'Restore Screen Updating
    Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with line breaks and paragraph breaks in bullet point document philiphunter7 Word 8 05-10-2020 11:51 PM
Need ca macro to remplace all line breaks inside all cells Chibiberu Excel Programming 4 03-30-2019 10:56 AM
Cross-post: fixing equations in one line mohsen.amiri Word 0 01-30-2017 10:52 AM
Macro for fixing abnormally formatted paragraph line breaks Replace paragraph-marks (line-breaks) in tables with a character-string Aztec Word VBA 2 04-02-2013 10:52 PM
Macro for fixing abnormally formatted paragraph line breaks Paragraph line breaks muymalestado Word 3 09-25-2011 05:06 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 02:58 PM.


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