Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
Good point with pasting without any formatting –  Nicu Zecheru Jun 24 '11 at 14:20
1  
+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... –  thkala Jun 25 '11 at 5:44
    
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 Jun 27 '11 at 20:09
    
@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... –  Brandon Jun 28 '11 at 1:20
    
Very nice! Thanks for the macro - I tried it out and it's exactly what I need... –  thkala Jun 28 '11 at 17:42

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|improve this answer
    
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... –  thkala Jun 23 '11 at 13:30
    
@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. –  Dmitry Selitskiy Jun 23 '11 at 21:40
  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!

share|improve this answer
    
+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 Jun 25 '11 at 5:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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