Word

Replace paragraph marks with SpaceAfterParagraph settings

Ease of Use

Easy

Version tested with

2003 

Submitted by:

mdmackillop

Description:

This code will replace paragraph marks (pilcrows) with appropriate spacing to retain the documents printed appearance. 

Discussion:

Sometimes you receive documents where all the spacing has been done with the Enter key. If the document requires editing, page margins changed or whatever, this can lead to excess spaces at the top of pages, Headings being separated from following text etc. By converting to SpaceAfterParagrah, these top spaces are eliminated and KeepWithNext etc. is much easier to apply. 

Code:

instructions for use

			

Option Explicit Sub RemParaMarks() 'Thanks to brettdj for the Replace 'Adjust loop if > 20 successive paramarks required Dim FntSize As Long, i As Long, DoSpace As Long Dim MyStr As String, Pilcrows As String FntSize = InputBox("Enter standard font size used", "Line spacing", 12) Application.ScreenUpdating = False MyStr = "^p" For i = 20 To 2 Step -1 Pilcrows = Replace(Space(i), " ", MyStr) DoSpace = (i - 1) * FntSize Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement.ParagraphFormat .SpaceAfter = DoSpace End With With Selection.Find .Text = Pilcrows .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll Next Application.ScreenUpdating = True End Sub

How to use:

  1. Copy the code above.
  2. Open Word.
  3. Alt + F11 to open the Visual Basic Editor.
  4. Insert-Module.
  5. Paste the code there.
  6. Close the VBE (Alt + Q or press the X in the top-right corner).
 

Test the code:

  1. Create a document with repeated Paragrah marks creating the spacing.
  2. Tools | Macro | Macros, and double-click RemParaMarks
 

Sample File:

ParaSample.zip 12.96KB 

Approved by mdmackillop


This entry has been viewed 211 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express