I'm trying to create a Word macro for add consistent paragraph spacing in my Word documents (Document page count = 10-20).
I tried this:
Code: Select all
Private Sub AfterSpaceSideHeads()
Dim oPar As Paragraph
Dim oRng As Word.Range
For Each oPar In ActiveDocument.Paragraphs
Set oRng = oPar.Range
With oRng
With .Find
.ClearFormatting
.Text = "[!.:]^013?{2}" 'Select side heading and first paragraph.
.MatchWildcards = True
.Execute
End With
Set oRng = oPar.Range
If oPar.Range.Information(wdWithInTable) = False Then
If oPar.Range.Paragraphs.Alignment = wdAlignParagraphLeft Then
If oPar.Range.ParagraphFormat.PageBreakBefore = False Then
If (oPar.Range.Paragraphs.SpaceBefore = 18) Then
.Select ' I need to select paragraph to apply this format
.ParagraphFormat.SpaceBefore = 6
.ParagraphFormat.SpaceBeforeAuto = False
.ParagraphFormat.SpaceAfter = 0
.ParagraphFormat.SpaceAfterAuto = False
Set oRng = Nothing
End If
End If
End If
End If
End With
Next
End Sub
But I'm troubling to add before space formatting to the paragraph. I attached a sample document with detailed comments.
Appreciate if someone can help. Thank you!