9

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.

  • 1
    Shouldn't replacing ^p^p with ^p work, seeing as a single blank line appears as some text^p^pmoretext? – jmetz Jul 31 '12 at 17:10
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.

  • 1
    If 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 Nov 15 '12 at 23:42
  • @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 Dec 17 '13 at 10:24
  • Simplest and best answer yet - unlike some blogs out there even talking about doing this in VBA! Heaven forbid. – Fandango68 Aug 28 '17 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.