title: Word VBA Macro to Clean Empty Paragraphs and Add space after & before
body: <p>I have this little macro whose purpose is to remove all the empty paragraphs (^p) and then select all paragraphs and add space after and before (6 points each).</p>
  
  <p>This is the code so far</p>
  
  <pre><code>Sub format()
  
  ActiveDocument.Range.Select
  
  ' Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
  .text = "^p^p"
  .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
  
  
  iParCount = ActiveDocument.Paragraphs.Count
  For J = 1 To iParCount
      ActiveDocument.Paragraphs(J).SpaceAfter = 6
      ActiveDocument.Paragraphs(J).SpaceBefore = 6
  Next J
  End Sub
  </code></pre>
  
  <p>However when I run it, everything becomes a single paragraph. Supose I have like (^p are empty paragraphs)</p>
  
  <pre><code>paragraph 1 
  ^p
  paragraph 2 
  ^p
  paragraph 3
  </code></pre>
  
  <p>I always get </p>
  
  <pre><code>paragraph 1 paragraph 2 paragraph 3
  </code></pre>
  
  <p>What am I doing wrong? Thanks!</p>