View Single Post
 
Old 04-21-2022, 11:48 PM
laith93 laith93 is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Dear Peterson, after applying your code, I think this portion of your code is not necessary at least according to my case , so I will remove it.

Quote:
Originally Posted by Peterson View Post

Code:
Sub CleanUpBlankLines() 
        
        ' Remove spaces between empty paragraphs, in preparation
        ' to remove paragraphs preceding numbers:
        .Text = "(^13)( {1,})(^13)"
        .Replacement.Text = "\1\3"
        .Execute Replace:=wdReplaceAll
        
        ' Remove empty paragraphs preceding numbers:
        .Text = "([^13]{2,})([0-9])"
        .Replacement.Text = "^13\2"
        .Execute Replace:=wdReplaceAll
   
 End Sub
Now, this code is ok
Code:
Sub GapRemoving4Paragraph()

' Finds paragraph marks and spaces between broken paragraphs and removes them

    Application.ScreenUpdating = False
    
    Dim oRange As range
         
    Set oRange = ActiveDocument.range

    With oRange.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWildcards = True
        
        ' Remove gaps in text:
        .Text = "([!0-9] )([^13 ]{1,})([!0-9])"
        .Replacement.Text = "\1\3"
        .Execute Replace:=wdReplaceAll
    
    End With
    
    With oRange.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWildcards = False
    End With
    
     Set oRange = Nothing

     Application.ScreenUpdating = True

 End Sub
But the only problem is that sometimes the lines of each paragraph are followed by a return mark, and this code is not removing them, as Word considers each line as a separate paragraph, so how to fix it, please?
See attached file
Attached Files
File Type: docx DemoLineParagraph.docx (18.3 KB, 13 views)
Reply With Quote