Merging and re-formatting paragraphs in Microsoft Word 2007

25,526

Solution 1

To get rid of the extra spaces, you can do a find/replace and type two spaces into the find box and one space into the replace box. Then just run that over and over until it no longer finds anything. However, if you have any intentional groupings of two or more spaces, this will also convert them to just a single space. But, typically two spaces are not needed even between sentences, unless you're using a mono-spaced font (see this question).

Side note: When I'm copying and pasting things into Word (e.g. from web pages or pdf documents), I've found that I can avoid some of the formatting wierdness by making sure that I'm just copying and pasting the plain text in without any formatting info from the source. I used to do this by first pasting it into a blank Notepad document, then recopying from notepad into Word. In Word 2010, you can skip that step by right clicking and using the "keep text only" option under the Paste Options. This might not help in your case though since there seem to be actual extra characters in the source you're copying from.

Edit:

I noticed that you mentioned the possibility of using a macro and wrote one up. Here's the VBA code:

Sub FixParagraph()
'
' FixParagraph Macro
'
'
    Dim selectedText As String
    Dim textLength As Integer

    selectedText = Selection.Text

    ' If no text is selected, this prevents this subroutine from typing another
    ' copy of the character following the cursor into the document
    If Len(selectedText) <= 1 Then
        Exit Sub
    End If

    ' Replace all carriage returns and line feeds in the selected text with spaces
    selectedText = Replace(selectedText, vbCr, " ")
    selectedText = Replace(selectedText, vbLf, " ")

    ' Get rid of repeated spaces
    Do
        textLength = Len(selectedText)
        selectedText = Replace(selectedText, "  ", " ")
    Loop While textLength <> Len(selectedText)

    ' Replace the selected text in the document with the modified text
    Selection.TypeText (selectedText)

End Sub

This macro replaces all carriage returns and newlines in the selected text with spaces, then gets rid of repeated spaces. So, you just highlight the text you want to fix and then run the macro. I've only tested this with Word 2010 since I don't have Word 2007, but I'm confident that it should work in 2007 as well.

To get the macro code into your document in Word 2007, first follow the "Show the Developer tab" instructions on this page. Then follow the "Write a macro from scratch" instructions on the same page (I used the name FixParagraph for my macro above). Once you've gotten to the code editor, you can just copy the body of the code above in. There are also instructions on how to run the macro on that same webpage.

Solution 2

  1. Press Ctrl+H to open Find and Replace
  2. Click on the Replace tab
  3. Click on the Find what field then on Special
  4. Select Paragraph Mark (you will see ^p in the Find field)
  5. In the Replace with field you don't have to type anything.

The problem is this will replace all paragraphs...

You can play around with those special characters. Good luck!

Solution 3

Main answer:

(inspired by Nicu Zecheru's answer)

  1. Select your text, that you where you want to remove paragraph breaks
  2. Press Ctrl-H
  3. Find: ^p (paragraph mark)
  4. Replace with what is appropriate (e.g. just space)
  5. Click Replace All. It will tell you how many replacements it made in selection and whether you want to continue beyond selection:
  6. Click No

That's it, now all paragraph marks are replaced in your selection.

Bonus: If you don't know how to make the non-printable symbols visible, follow these steps:

You need to make the non-printable symbols visible - click on this icon in the toolbar: enter image description here

Now you will see paragraph marks, spaces, etc:

enter image description here

Remove the paragraph marks (highlighted yellow in the picture) as required to fix the text. Then you can format the inter-line spacing as required through the paragraph properties.

P.S. screenshots are from Word 2010 but symbols and functionality will be the same in any Word's version.

Share:
25,526

Related videos on Youtube

thkala
Author by

thkala

Updated on September 18, 2022

Comments

  • thkala
    thkala almost 2 years

    After a copy/paste mishap in Microsoft Word 2007, I ended up with text looking like this:

    This line   breaks up here
    
    continues here, and    so on
    
    here, when    it should all be
    
    in a    single line without
    
    all the random    whitespace.
    

    I confirmed that there are paragraph separators and extra whitespace between each line - probably due to hard-coded newlines in the original source.

    1. Is there a (preferrably easy) way to merge paragraphs in Microsoft Word?

    2. Is there a way to re-format a paragraph so that extraneous whitespace is removed? I can change the flush style, but the whitespace remains.

    I (obviously?) do not have any experience with Word, being more of a TeX person, but I have been searching Google and crawling the menus for a few hours and I have yet to find a solution...

  • thkala
    thkala about 13 years
    I was aware of that button - that was how I confirmed the existence of the paragraph breaks and extra whitespace, as mentioned in my question. The problem is that doing the clean-up manually is way too arduous, even when I can see what I am doing. I was hoping for a way to do this automatically...
  • Dmitry Selitskiy
    Dmitry Selitskiy about 13 years
    @thkala Ok, sure, my bad. Please clarify your question telling us that you can see the paragraph marks :) To the question: Nicu's suggesting got me thinking! I'll update the answer accordingly.
  • Nicu Zecheru
    Nicu Zecheru about 13 years
    Good point with pasting without any formatting
  • thkala
    thkala about 13 years
    +1 Not quite what I was hoping for, but apparently that is as far as Word will go. Perhaps I could try a macro to do this right...
  • thkala
    thkala about 13 years
    +1 The best answer so far. It's quite unfortunate that in Word I need to jump through all those hoops just to do what my mail client does with a single keyboard shortcut...
  • Brandon
    Brandon about 13 years
    Yeah, it seems to me like Word should default to pasting plain text in so that the formatting matches the context of the document (font, font size, color, etc). I think people want to do that more often than having Word attempt (with limited success) to copy the formatting from the source. But, c'est la vie. I use LaTeX for most of my writing nowadays. It's really nice once you know your way around it, but it has a fairly steep learning curve. I've made good use of the LaTeX Stack Exchange site while learning it.
  • Brandon
    Brandon about 13 years
    @thkala I wrote up a little macro that takes care of both the line breaks and extra spaces and added it to my answer. Of course, it involves the extra step of copying the macro code into your document...
  • thkala
    thkala about 13 years
    Very nice! Thanks for the macro - I tried it out and it's exactly what I need...