Created
September 30, 2016 06:24
-
-
Save tdalon/2817ced08d066cee0b0a821ec0b897b0 to your computer and use it in GitHub Desktop.
MS Office Word VBA Macros to delete empty paragraphs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub DeleteEmptyParagraphs() | |
Dim oPara As Word.Paragraph | |
For Each oPara In ActiveDocument.Paragraphs | |
If Len(oPara.Range) = 1 Then oPara.Range.Delete | |
Next | |
End Sub | |
Sub DeleteEmptyParagraphsWithSpaces() | |
Dim oPara As Word.Paragraph | |
Dim var | |
Dim SpaceCounter As Long | |
Dim oChar As Word.Characters | |
For Each oPara In ActiveDocument.Paragraphs | |
If Len(oPara.Range) = 1 Then | |
oPara.Range.Delete | |
Else | |
SpaceCounter = 0 | |
Set oChar = oPara.Range.Characters | |
For var = 1 To oChar.Count | |
If Asc(oChar(var)) = 32 Then | |
SpaceCounter = SpaceCounter + 1 | |
End If | |
Next | |
If SpaceCounter + 1 = Len(oPara.Range) Then | |
' paragraph contains ONLY spaces | |
oPara.Range.Delete | |
End If | |
End If | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment