![]() |
#1
|
|||
|
|||
![]()
I have found code, which delete empty paragraphs. But it doesn't do anything. Probably too old version doesn't find "^l"
Code:
Sub Deleemptylines() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^l" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .MatchFuzzy = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub Code:
Sub RemoveBlankParas() Dim oDoc As Word.Document Dim i As Long Dim oRng As Range Dim lParas As Long Set oDoc = ActiveDocument lParas = oDoc.Paragraphs.Count ' Total paragraph count Set oRng = ActiveDocument.Range For i = lParas To 1 Step -1 oRng.Select lEnd = lEnd + oRng.Paragraphs.Count ' Keep track of how many processed If Len(ActiveDocument.Paragraphs(i).Range.Text) = 1 Then ActiveDocument.Paragraphs(i).Range.Delete End If Next i Set para = Nothing Set oDoc = Nothing Exit Sub End Sub 1. If only one empty line, do nothing. If more then one, delete all except one. 2. The same as first (replace more then 1 emtpy lines on only 1 empty), but do it only if that empty lines are in the end of the document (no has any text after them). For second variant i found: Code:
Sub Delemtpylinatend() Dim opar As Paragraph Set opar = ActiveDocument.Range.Paragraphs.Last While Len(opar.Range.Text) = 1 Set opar = opar.Previous opar.Next.Range.Delete Wend End Sub But it deletes all empty. How can i modify to leave one empty par? |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
gavi12 | Word VBA | 1 | 04-04-2020 05:42 AM |
![]() |
vibor | Word VBA | 9 | 05-03-2015 05:42 AM |
![]() |
dexter30 | Word VBA | 2 | 08-05-2013 08:37 PM |
regular expressions for empty lines | eNGiNe | Word | 1 | 01-21-2013 06:38 AM |
Deleting empty lines | lostsoul62 | Word | 5 | 04-16-2012 04:55 AM |