Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 04-21-2022, 11:48 PM
laith93 laith93 is offline Remove extra space before a paragraph and return it to previous paragraph Windows 10 Remove extra space before a paragraph and return it to previous paragraph Office 2019
Competent Performer
Remove extra space before a paragraph and return it to previous paragraph
 
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
 

Tags
word 19, word vba, word vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection drrr Word VBA 2 08-24-2021 03:05 AM
Remove extra space before a paragraph and return it to previous paragraph Delete comma and space after blank merged value. Also remove Previous space and word before blank Alex1s85 Mail Merge 4 01-18-2020 11:30 PM
Remove extra space before a paragraph and return it to previous paragraph Large first character in paragraph causing extra line space dustnik Word 11 09-04-2019 12:47 AM
Add a heading for each paragraph depending on the previous paragraphs numbering herman Word 4 07-15-2019 09:48 PM
Remove extra space before a paragraph and return it to previous paragraph Word thinks 1 sentence is 2 paragraphs and won't let me delete the extra paragraph symbol jrasicmark Word 1 12-05-2014 01:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:39 AM.


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