Removing Extra Paragraph Marks

by Allen Wyatt
(last updated August 20, 2016)

12

There may be times when you are working with a document when you have a need to remove extra paragraph marks. This is particularly true if you are working with an ASCII file or a file that may have originally been formatted with another word processor. This process of manually removing extra paragraph marks can be very time consuming.

If you find yourself in this situation, you may find this macro of interest. It removes extra paragraph marks from a document. When it is completed, there should not be even two paragraph marks in a row in your document.

Sub ReplacePara()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    While Selection.Find.Found
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.TypeBackspace
        Selection.MoveLeft Unit:=wdCharacter, Count:=2
        Selection.Find.Execute
    Wend
End Sub

There are two parts to this macro. The first part—which relies on the Selection.Find method—uses Word's built-in find and replace capabilities to find all instances of two paragraph marks in sequence. The macro doesn't replace the sequential paragraph marks; it simply finds them. Then the second part of the macro kicks in—using the Selection.Find.Found—property to delete the second of the two sequential paragraph marks.

The reason this approach is taken is because it leaves the formatting correct on the remaining paragraph mark. For instance, if the two sequential paragraph marks use different formatting from each other, the formatting of the first paragraph mark remains unchanged. If you simply replaced the sequential paragraph marks with a single paragraph mark, it is possible that you may not have the formatting exactly as you want when the replacing is finished.

Note that Selection.Find.Found is used as a "flag" for the While loop. This property reflects the status of the latest Find operation. If True then the search was successful; if False, then there was nothing found (and, therefore, nothing to change).

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (998) applies to Microsoft Word 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Sticking with the Dashes

By default, dashes don't "stick" to the text that follows them. Here's one way around this normal formatting convention.

Discover More

Inserting the Total Number of Characters in Your Document

One of the things that Word keeps track of regarding your document is the number of characters it contains. Using the ...

Discover More

Changing the Ribbon's Size and Look

The Ribbon, while debatably handy, can be downright difficult to use for those with a sight impairment. Here are some ideas ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Entering a Page Break from the Keyboard

Need to force Word to move text to the top of the next page? It's easy when you use the keyboard shortcut for a page break.

Discover More

Inserting Today's Date

When writing letters, reports, or other date-dependent documents, you need to regularly insert the current date in the ...

Discover More

Jumping to a Specific Page

Want to jump to a particular page in your document? Word makes it easy; just pull up the Go To tab of the Find and Replace ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 0?

2016-10-06 08:07:55

Lee Batchelor

Thanks for the tip, Truis! I shall modify my macro.

- Lee


2016-10-05 23:37:04

Truis

Great stuff! This code is exactly what I needed for a macro that tidies up the formatting of text pasted in from elsewhere. In this case, it's important to use Backspace, because I want Word to retain the formatting of the second paragraph mark, not the first. That bit's working well.

Unfortunately, I'm having trouble with the While/Wend, because it's deleting *too* many characters, not just the paragraph marks. I think that's because the source of what my macro is pasting in (as unformatted text) is the content of a Content Control. Two steps forward, one step back...!

Tip! If finding "^p^p" finds no results (when you know they exist), try finding "^013^013" instead. That's the full character code, rather than the "^p
", which is like an internal shortcut key.


2016-08-28 08:49:47

Lee Batchelor

Yes, the macro crashes Word 2007 too, when there is a table in the document.

I tried the Find and Replace method with or without a table. It doesn't get rid of the empty paragraphs in Word 2007. Why not?

I typed:
Find what: ^p^p
Replace with: ^p

It found two paragraphs in a row (the first with content, the second with nothing, which must be deleted), and it didn't do anything!!


2016-08-27 11:49:02

Lyn Imeson

This macro doesn't seem to work if there are tables in the file. It makes Word crash.
Could anyone suggest a modification?


2016-08-25 08:08:47

Lee Batchelor

Good catch, Lisa!

I just ran the macro without removing the space, and only those empty paragraphs without the extra space were cleared.

I wonder if someone can modify this macro to account for the extra space.


2016-08-24 11:53:31

Lisa Herider

I have found many paragraph marks preceded by a spaceband. Before you run this macro, do a search/replace for the spaceband and ^p in your search string replacing with just the ^p. That way when you run the macro it will find all the paragraph returns.


2016-08-22 12:30:58

Macro is faster

Using a macro is much faster if someone hit enter 20+ times. Set it one and give it a keyboard shortcut, or assign a button to it in the QAT and you are all set. Saves a ton of time.


2016-08-22 10:44:29

Sarita King

Macro Schmacro..do a find and replace with the following
FIND ^p^p
REPLACE ^p

run it until it stops.
Note bonus the code for tab is ^t


2016-08-22 03:34:59

George JasonSmith

I agree with Min (below) and have been using fAnd and replace to do this for years. also I find it easier to type ^p ^p into the find box and ^p into the replace, rather than navigating the Choose box


2016-08-21 09:09:18

Lee Batchelor

Agreed, Min. I've used your method too. I've also noticed it can mess up the formatting of some paragraphs that have styles applied when I fill in the Replace field with nothing (leave it blank). By placing one paragraph mark in the Replace box, you still have one empty paragraph where the user had two originally, correct? Empty paragraphs are a no-no.


2016-08-20 10:01:49

Min Edwards

Actually you don't need a macro to do this do you? I take out those multiple paragraph marks just with Find/Replace. Some of my clients add multiple marks instead of a page break so you can imagine how many paragraph marks they insert. With Find choose Special then choose Paragraph Mark, then another paragraph mark. In the Replace box, just put one Paragraph mark. You may have to do this multiple times if there are lots of para marks strung together.


2016-08-20 09:19:40

Lee Batchelor

What a wonderful macro! I often import documents where the person has used the Enter key to create extra paragraph spacing, instead of controlling the Before and After paragraph spacing using styles. So many people treat word processors like typewriters, which is mostly wrong.

It's so sad that to create handy macros like this one, we must learn a very complex language like VBA. We can’t expect Microsoft to anticipate all our individual writing needs, but if we only had a tool that easily lets us create macros, we could customize Word the way we want it. The Record Macro tool is handy but very limited.

Thanks for this wonderful macro!


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.