Microsoft Word: delete blank lines or empty paragraphs

9

1

Ok, so if you search for "word delete blank lines" you get a lot of stuff but they are mostly talking about the special characters to replace two successive empty paragraphs, i.e. replace ^p^p with ^p. And before you ask: no, it doesn't work to replace ^p with an empty replacement, because ^p matches a carriage return and not a paragraph (i.e. it will replace all carriage returns in a document, transforming it into one long text).

However, I do have empty lines which are just lines with no text in front of a carriage return: in terms of regular expression I would describe this as

^$

Or in terms of HTML, I'm talking about this:

<p>Some text</p>
<p></p>
<p>some more text</p>

And in vi I would simply delete blank lines. But I cannot export the word, modify text and import, it's using heavy formatting, etc.

Using Microsoft Word 2007.

mark

Posted 2012-07-31T16:51:36.483

Reputation: 1 722

1Shouldn't replacing ^p^p with ^p work, seeing as a single blank line appears as some text^p^pmoretext? – jmetz – 2012-07-31T17:10:04.853

Answers

10

@mutzmatron is right, replacing ^p^p with ^p actually is the proper way.

However, when my documents contains e.g. ^p^p^p^p or similar, it won't pick them all up and will again leave ^p^p. So I've to run this search/replace operation a few times until all cases have been covered.

mark

Posted 2012-07-31T16:51:36.483

Reputation: 1 722

Simplest and best answer yet - unlike some blogs out there even talking about doing this in VBA! Heaven forbid. – Fandango68 – 2017-08-28T23:59:40.703

1If you have many sequences of many blank lines (paragraphs), consider replacing ^p^p^p^p with ^p until it doesn’t find any more ^p^p^p^p’s, then do the ^p^p -> ^p thing. – Scott – 2012-11-15T23:42:45.510

@mark This does not seem to work if there are two consecutive paragraphs (^ps) of different styles, whether it be a difference in paragraph style or character style. – Jonathan Komar – 2013-12-17T10:24:51.143

0

Another way by using Wildcard:

Tick "Use wildcards" in search and replace window.

search: (^13)^13{1,}.

replace:\1.

^13 is the paragraph mark under wildcard mode. It would search for one paragraph mark followed by at least one other paragraph mark(s). Only keep the first paragraph mark, which marks the end of a non-empty line.

Z.Zen

Posted 2012-07-31T16:51:36.483

Reputation: 91