Finding and replacing non-printing characters (such as paragraph marks) and text formatting

Article contributed by Dave Rado

  1. Finding & Replacing non-printing characters
  2. Finding & Replacing formatting
  3. Finding & Replacing other special characters
  4. Controlling which sections of the document are acted upon
  5. Major gotchas
  6. Using wildcards
  7. Related articles

1.

Finding & Replacing non-printing characters

1.

On the Edit menu choose Replace.

2.

In the Find & Replace dialog, click in the Find What box and Click the More button.

3.

Either type the character code you need (for instance, you can type ^p in the Find What box to represent a paragraph mark); or, if you didn't happen to know that the character code you needed was ^p, click the Special button, and select an item from the list.

If you use the Special button, a special code representing the non-printing character will be inserted in the Find What box.  For instance, if you selected Paragraph Mark, ^p will be inserted.

4.

Do the same in the Replace With box. For instance, to replace all manual line breaks with paragraph marks, you would replace ^l with ^p.  Or to delete all manual page breaks, replace ^m with nothing.  Once you know the special codes you can just type them; but the Special button is invaluable at first!

Note: these character codes are case-sensitive: for instance, ^P is not valid.

5.

If you leave the Replace With box empty, the search string in the Find What box will be deleted from the document or selection.

6.

You can type additional text around the special codes.  For instance, to delete all instances of a full stop [period] at the end of a paragraph, (in a bulleted list, for instance), you would select the area you want to do the replacement in (or not, if you want to do it in the entire document); in the Find What box, type:

.^p

leaving the Replace With box empty; then click Replace All.

2.

Finding & Replacing formatting

To replace text that has particular formatting

To find text that has particular formatting and replace it with different text, but without changing the formatting, you would need to carry out the following steps: 

1.

On the Edit menu choose Replace.

2.

In the Find & Replace dialog, click in the Find What box and type the text you want to search for.

3.

Click the More button.

4.

Click on the Format button, and select the options as required.

5.

In the Replace With box, type the text you want it to be replaced with and click Replace All.

For example, if you wanted to find all instances of the word Hi that were formatted in the Heading 1 style, and replace them with the word Ho, you would need to carry out the following steps:

1.

In the Find What box, type Hi.

2.

Click More, then Format, then Styles.

3.

Find the Heading 1 style in the list and click OK.

4.

In the Replace With box, type Ho

5.

Tick the Find whole words only checkbox

6.

Where is says Search, make sure it's set to All.

7.

Click Replace All.

To replace formatting

To find all instances of the word Hi that were formatted in bold and remove the bold formatting, you would need to carry out the following steps:

1.

In the Find What box, type Hi.

2.

Click More, then Format, then Styles.

3.

Find the Heading 1 style in the list and click OK.

4.

Leave the Replace With box empty.

5.

Tick the Find whole words only checkbox

6.

Where is says Search, make sure it's set to All.

7.

Click Replace All.

To replace all instances of the Normal style with the Body Text style you would need to:

1.

Leave both the Find What and Replace With boxes blank.

2.

With your cursor in the Find What box, click More, then Format, then Styles.

3.

Find the Normal style in the list and click OK

4.

With your cursor in the Replace With box, click Format, then Styles, find the Body Text style in the list, and click OK

6.

Where is says Search, make sure it's set to All.

7.

Click Replace All.

3.

Finding & Replacing other special characters

 

It's easy to find and replace characters such as ©, é, ä, or any character listed in the Insert + Symbol dialog with the Font box set to (normal text) and the Subset box set to Basic Latin, (or to put it another way, any character included in the ANSI character set). Just insert the character(s) into your document and then cut and paste them into the dialog.

The easiest way is to insert both the find and replace strings into your document first, next to each other, so you can paste both – using Ctrl+V – into both the Find what and Replace with boxes and delete as appropriate.

So if you want to replace Andre with André, type AndreAndré, paste that into both boxes of the dialog, and delete André from the first box and Andre from the second.

For other symbols, such as Upper Unicode characters, and symbols from decorative fonts such as Symbol and Wingdings, things get a little more complicated, but it can be done. For the details, see Finding and replacing symbols.

 

Sometimes when you paste in from other applications, non-printing characters paste in that display as paragraph marks but don't behave like proper paragraph breaks should – they behave like manual line breaks. The character code for a paragraph mark is 13 (as can be shown be selecting one and running a macro containing the line: MsgBox Asc(Selection.Text)).

Replacing ^013 with ^p fixes the problem.

 

Sometimes you might want to replace all "keyboard quotes" in a document with smart quotes. The easiest way to do so is to simply replace " with " (i.e. replace a keyboard quote with itself) and then ' with ' (i.e. replace a keyboard apostrophe with itself), making sure you have smart quotes turned on (under Tools + AutoCorrect; AutoFormat As You Type tab).

To  replace smart quotes with "keyboard quotes", do the same Find and Replace operations, but with smart quotes turned off.

4.

Controlling which sections of the document are acted upon

If you click on the More button and look in the Search box, it will be set to Down, Up or All.

By default, if nothing in the document is selected, it will be set to All, whereas if something is selected, it will be set to Down.

If it's set to Down (or Up), it will act upon the selection only; then ask if you want to continue searching the rest of the document.  Even if you click Yes, it will ignore the Headers and Footers.  (If nothing is selected it will search to the beginning or end of the document, then ask if you want to search the rest – but will still ignore the Headers & Footers).

If it's set to All, it will check everything without asking, including the Headers and Footers.  So if you want to do a replace on the entire document, you must remember to click More and then set the Search box to All if it isn't already.

If you're searching down, by the way, you can quit the dialog at any point and use Shift+F4 to repeat the Find; and you can go down as well as up using the Browse arrows at the bottom of the vertical scrollbar to repeat the Find (this tip is more relevant to Finding than to Replacing, but seemed worth throwing in for good measure!).

By now you'll be starting to realise that to use the Find & Replace dialog properly you must always begin by clicking the More button!  So why have the button at all, you  may ask – it's a major PITA having to click it every single time!  If you feel that way, may I suggest you contact http://support.microsoft.com/contactus/.  If enough of us ask, who knows, they might listen!

5.

Major gotchas

If you Find & Replace formatting, the settings you chose are sticky – they won't be reset until you do another Find & Replace and click the No Formatting button.

Settings such as Find entire words only are equally sticky.

When you do a replace and it finds nothing when you expected the opposite, the reason is almost always that you forgot to clear all those sticky settings.  Another reason to contact http://support.microsoft.com/contactus/ – but in the meantime, you can assign a macro to a toolbar to clear the settings from the Find dialog.  Then you can just click on the toolbar button after each Find & Replace.

Or better still, you could write a macro to intercept the EditFind and EditReplace commands and include the code to clear the settings in your macro.  Then you won't have to remember to click on a button.

6.

Using wildcards

Using wildcards allows you to perform extremely powerful Find & Replace operations in Word. This is covered separately in the article: Finding and replacing characters using wildcards.

7.

Finding and replacing characters using wildcards

How can I insert special characters, such as dingbats and accented letters, in my document?

Delete html tags or sgml tags or other bracketed tags (<example>) from a document without affecting other text

Finding and replacing symbols

How to replace text in quotation marks with italic or highlighted text minus the quotes

Transpose dates from mm/dd/yy to yy/mm/dd
Example: from 12/17/85 to 85/12/17

Eliminate carriage returns (paragraph marks) at the end of each line but not at the end of each paragraph

How to put a page break in front of each Heading 1 paragraph

How to modify the path or filename in a series of hyperlink fields

Replace any instance of the left square bracket character [ that happens to be the fifth character in a paragraph

Remove all empty paragraphs from a document

How to use Edit Find to select everything from where the cursor is to the first found item