Saturday, 19 January 2008

MS Word: replace, reformat, rejoice

Here is the scenario, you have copied some text from somewhere and pasted it into Word; however, the text ends up looking something like this.

To see the cause of this problem, press the 'Show/Hide ' button. As shown, the original text has carriage returns - as indicated by the '¶' marks - at the end of the original lines. When this text was pasted into word the lines were no longer the same length, so, the carriage returns were in the wrong place.

The solution to this problem is to replace the carriage returns with spaces. You can do this manually, or use the replace feature in Word. To open the 'Find and Replace' dialog box, pull down the 'Edit' menu and select 'Replace' - you may have to click the double arrows at the bottom of the menu to display all the entries on the menu - or you could hold down the Ctrl key and press H.

Each special character has its own code associated with it. For the carriage return this is '^p', for Tab it is '^t' and so on (you can see them all by pressing the 'More' button on the 'Find and Replace' dialog box - this will display more options - and press the 'Special' button.

The text we are editing is broken into various paragraphs with an empty line between them. In order to maintain this separation of paragraphs, we need to mark all the places where one return follows another. I usually use two tildes '~' to mark these, because that rarely occurs in a text. Fill in the fields as below and press the 'Replace all' button.


A dialog box will be shown telling you how many replacements have been made. Press OK to close it. The text will then look like this...

With the separation of paragraphs marked we can now remove all those superfluous returns. Enter '^p' in the Find what: field and a space in the Replace with: field.


Press 'Replace All' again and OK when you are told how many replacements have been made. The text will then look like this...

We need to return the paragraphs to their original form. To do this replace all the occasions of '~~' with two carriage returns, as in the following image. Again, press 'Replace All'.


The text should now look like this. We are very close to what we want, except that there are some superfluous spaces in the quote at the bottom.

To remove these, go to the 'Find and Replace' dialog box again, and enter two spaces in the Find what: field and one space in the Replace with: field. Keep pressing the 'Replace All' button until there are no more examples to replace. The text should now look like this: nicely formatted with all the separate paragraphs maintained.

6 comments:

CelloBella said...

THAT is a great post. :)

sir jorge said...

great post indeed, i liked it a lot.

Magdalen Islands said...

Wow! Great tips..., now I have to translate it into WordPerfect..., lol! I've been doing the manual thing all along..., pain!

Edvin said...

That post of yours saved my day (and especially the morning ^_^ ) Thank you and good luck to you!

p.s.
for some rather stupid reason, my old Words 2000 version does not allow me to put the "field" or "white space" or "empty space" into the "replace with" box. It only allows "Nonbreaking space" which is visually the same as "space" (but may cause problems, if a program processes the text later on)

maheswari said...

Hello!!.... This post is likeable, and your blog is very interesting, congratulations.

Computer Reformat

Stepterix said...

Thanks for the comments