Remove all empty paragraphs

S

Sandi V

Good afternoon - I am trying to create a macro that cleans up a messy
document. What I've got so far is from recording a couple of short macros &
looking at the resulting code.

I recorded a macro to find all instances of two empty paragraphs & replace
with one, which gives me:

With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p

I want this to loop until Word no longer finds two empty paragraph marks.
Can somebody help me with this? (My VBA skills are not great). Thanks in
advance!

Sandi
(code follows)

Sub FixDoc()
'
'Copy everthing but the last paragraph mark
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Copy

'New blank doc, paste unformatted
Documents.Add Template:="z:\templates\NewBlank.dot", NewTemplate:=False, _
DocumentType:=0
Selection.PasteAndFormat (wdPasteDefault)

'Remove direct formatting
Selection.WholeStory
Selection.Font.Reset
Selection.ParagraphFormat.Reset
WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1

With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

'Apply a Style
Selection.Style = ActiveDocument.Styles("TR Body Text 1,B1")
End Sub
 
D

Doug Robbins - Word MVP

In the Replace dialog, click on the More button and then check the Use
wildcards box and replace the ^p^p that you have with ^13{2,}

Leave the ^p in the Replace with control.

For more information on using Wildcards, see the following page of fellow
MVP Graham Mayor's website

http://www.gmayor.com/replace_using_wildcards.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top