NAVIGATING THROUGH DOCUMENTS

FIND AND REPLACE

Find and Replace Quickly

The Annoyance:

I seem to spend half my time with the Find and Replace dialog box open . I find the first instance of the search term; close the dialog box, check the term , and make any edits needed; open the dialog box again and find the next instance; lather, rinse, and repeat. I guess I just feel it could be easier.

The Fix:

And it can. First, the Find and Replace dialog box is modeless, so you can edit your document without closing the dialog box. All you need to do is get the dialog box out of the way so that you can perform the edits. That saves time, because you don't have to invoke the dialog box again to find the next instance.


Tip: A modeless dialog box is one that you can leave open on screen while you continue to work in the application. Most dialog boxes are modal , which means that you have to dismiss them before you can do any more work in the application.

Second, when you perform a search, Word sets the browse object (see "Navigate with Browse Objects," later in this chapter) to Find and uses that search term. What that means is that you can find the next instance of the term by clicking the Next button (see Figure 3-10) below the vertical scrollbar or find the previous instance of the term by clicking the Previous button. Even easier and faster, you can press Ctrl+PageDown to find the next instance and Ctrl+PageUp to find the previous instance.

Figure 3-10. When you search, Word changes the Previous and Next buttons to Previous Find/GoTo and Next Find/GoTo.

Replace Styles and Formatting

The Annoyance:

We have a standard template for our manuals that has a style for every occasion and a few dozen styles for the stockpot. So far, so good. But now we've acquired one of our competitors and need to "translate" all their documents from their three templates to our template. And yes, you've guessed it: I get to do the "translation."

The Fix:

If you know VBA, you can write a quick macro to make this change. But if you don't know VBA, you can make the changes easily enough by using Find and Replace to replace each style from their templates with the corresponding style from your template. If you record a macro of yourself performing the replacements , you can then run it on other documents.

To replace one style with another style:

  1. Make a two-column list of the styles you want to change and what you want to change them to. You can do this on paper, or in a Word table if you find that easier.

  2. Open a document based on one of the other company's templates.

  3. Choose Tools Templates and Add-Ins, click the Attach button, select your companys standard manual template, and click the Open button. Check the "Automatically update document styles" box, and then click the OK button.

  4. Choose Edit Replace (or press Ctrl+H) to display the Replace tab of the Find and Replace dialog box.

  5. Click the More button if the dialog box doesn't include the Search Options section.

  6. If there are any formatting details under the "Find what" box, click the No Formatting button to remove them.

  7. Click the Format button and choose Style from the shortcut menu to display the Find Style dialog box (see Figure 3-11). Click the first of the styles you want to replace, and then click the OK button.

    Figure 3-11. Find and Replace provides an easy way of changing one set of styles to another throughout a document.

  8. Press Tab to select the "Replace with" box. If the box contains text, press Delete. If there are formatting details under it, click the No Formatting button to remove them.

  9. Click the Format button and choose Style from the shortcut menu to display the Replace Style dialog box. Choose the corresponding replacement style, and then click the OK button.

  10. Click the Replace All button to replace all instances of the style under the "Find what" box with the style under the "Replace with" box.

  11. Select the next search style and the next replacement style, and repeat the replacement. Do this for all the remaining styles you wish to replace.

Replace Dumb Quotes with Smart Quotes

The Annoyance:

Our reps are supposed to send me their reports as Word documents attached to email messages, but of course what most of them do is just type the reports directly in email. Some of the reports are so short, I'm sure they're at the beach (or bar, or both) on their BlackBerries. Anyway, I can copy the text from the emails into Word, but I need to smarten up the straight quotes in the emails. And boy, do they use a lot of those quotes!

The Fix:

Provided that you've got the "'Straight quotes' with 'smart quotes'" box on the AutoFormat As You Type tab of the AutoCorrect dialog box (Tools AutoCorrect) selected, you can change all these quotes quickly using Replace. Copy all the text into your document, choose Edit Replace (or press Ctrl+H), and run two replace operations. In the first, replace " with ". In the second, replace ' with '. Word will automatically put in the smart quotes for you.

Replace with a Subscript

The Annoyance:

Word can't search and replace a sub- or superscripted character within a wordfor example, replacing "SO2" with "SO 2 "; instead, it just subscripts the whole word. This is a major annoyance if you're editing a technical paper where the offending term crops up dozens of times.

The Fix:

You're right, you can't do this directly with Find and Replace, because if you specify formatting for the "Replace with" text, it applies to the whole of that text. But what you can do is replace with the contents of the Clipboard. To do so, enter the text you want in your document, select it, and press Ctrl+C to copy it. Press Ctrl+H to display the Find and Replace dialog box, type the search text into the "Find what" box, and type ^c in the "Replace with" box. Word then replaces the found items with the contents of the Clipboard.

Another trick that's sometimes useful is to use two replace operations: one to isolate the text you want to affect, and the second to apply the change. This technique also works for replacing "SO2" with "SO 2 ". In the first replace operation, replace "SO2" with "SO" concatenated to a text string that will distinguish the "2" from instances of "2" that don't need to be changedfor example, "SOzx2zx." In the second replace operation, replace "zx2zx" with a subscript "2."


Tip: You can also use a macro to perform this type of replacement. See "Perform Find and Replace with Complex Formatting" in Chapter 8.

Perform a Two-Step Replace

The Annoyance:

Okay, picture this: I've got a 500-page document with several thousand references to our product, the Bovine Super Defibrillator. Only sometimes it's just called the Super Defibrillator. I need to change all the instances to "Bovine Super Defibrillator." But if I do a Replace All, all the instances that already have "Bovine" change to "Bovine Bovine Super Defibrillator," which I don't want. And if I don't do a Replace All, I need to accept or reject the replacements one at a time.

The Fix:

It's okay. Do the Replace All. Then do a Replace All of "Bovine Bovine" with "Bovine." Problem solved .

Find Any Character, Digit, or Letter

The Annoyance:

Find and Replace isn't flexible enough! I need to check references to a bunch of different product codes, CP408 through CQ917. As you can imagine, searching for "C" with "Match case" on finds me every capital C in the document. I want a better way!

The Fix:

There are two ways you can do this. The easiest way is to search for c^$^#^#^# , which finds a C followed by any single letter and then three digits. To find special items, use the codes explained in Table 3-1. You can enter them by clicking the Special button in the Find and Replace dialog box (see Figure 3-12) when the "Use wildcards" box is unchecked, but once you find how useful they are, you'll find it quicker to type them.

Table 3-1. Special codes for Find and Replace

Code

Meaning

^p

A paragraph mark.

^t

A tab.

^?

Any single character (letter or number). For example, ^p^t^? finds any character preceded by a tab that appears after a paragraph mark.

^#

Any digit. For example, ^p^# finds a paragraph that starts with a number.

^$

Any single letter (not a digit).

^^

A caret (the single caret is used to identify other codes).

^%

A section character ().

^v

A paragraph character (-not a paragraph mark).

^n

A column break.

^+

An em dash ().

^=

An en dash ().

^e

An endnote mark.

^d

A field.

^f

A footnote mark.

^g

A graphic.

^l

A manual line break.

^m

A manual page break.

^~

A nonbreaking hyphen.

^-

An optional hyphen.

^s

A nonbreaking space.

^b

A section break.

^w

Whitespace (one or more spaces, one or more tabs, or a combination of the two).


Figure 3-12. The Special pop-up menu in the Find and Replace dialog box provides an easy way to enter the codes for special items.

The other way is to use regular expressions , or combinations of text and wildcards. Check the "Use wildcards" box and enter C[P-Q] (in capitals, as it's case-sensitive) in the "Find what" box, then click the Find Next button. See "Change 'Firstname Lastname' to 'Lastname, Firstname'," later in this chapter, for details.

Strip Blank Paragraphs from a Document

The Annoyance:

Two hard returns after each paragraph, three hard returns after each heading, and four hard returns before a heading...will someone please tell my colleagues, many happy returns, but the typewriter is dead? I know I'm wasting time by telling them about styles, but if only they'd cut down on thumping the Enter key so many times, I'd be a far happier camper.

The Fix:

Relax, you can fix this easily enough. Choose Edit Replace, type ^p^p in the "Find what box and ^p in the "Replace with" box, and click the Replace All button. When Word tells you how many replacements it has made, click the OK button, and then click the Replace All button again. That should take care of the problem: the first pass reduces each set of four hard returns to two, each set of three hard returns to two, and each set of two hard returns to one. The second reduces each remaining set of two hard returns to one.

Change "Firstname Lastname" to "Lastname, Firstname"

The Annoyance:

Beautiful. Just beautiful. The chairperson just handed me the list of our members ' names and askedwell, told me to change it from "Firstname Lastname Membershipnumber" to "Membershipnumber Tab Lastname, Firstname." My future flashed before me, and it's looking tedious enough to bore a well.

The Fix:

Word can do this for you. Open the document and select the part of it that contains the names. (If the whole document is the names, you don't need to select anything. Otherwise, select only the names, as the pattern matches any sequence of three words.) Choose Edit Replace (or press Ctrl+H) to display the Replace tab of the Find and Replace dialog box. Clear any formatting from the "Find what box and the "Replace with" box. Enter (<*>) (<*>) (<*>) in the "Find what" box, with a space between each closing parenthesis and the opening parenthesis following it. Enter \3^t\2, \1 in the "Replace with" box, including the space after the comma. Check the "Use wildcards" box and click the Replace All button. Word changes the position of the words.

Table 3-2. Wildcard characters for searching in Word

Wildcard

Meaning

Example using the wildcard

?

Any one character

sh?p finds "ship" and "shop".

*

A string of characters (including spaces)

w*d finds strings of text that start with "w" and end with "d," such as "wad," "wood," " wicked ," and part of "stra wberry d onut." This also finds "wd," because the string can have zero length.

<

The beginning of a word or group of characters

<wear finds "wear," "wearisome," and other words with "wear" at the beginning, but not "swear" or "sportswear."

>

The end of a word or group of characters

>ble finds "horrible," "terrible," and other words that end in "ble," but not words such as "bleary" or "ablest."

()

Group wildcard characters

(<*>) finds a word by specifying a group with the start of the word, the * wildcard to find a string of characters, and the end of the word.

[]

One or more of the characters specified

w[aeu]d finds "wad," "wed," and "weed," but not "wood," because "o" is not included in the bracketed selection of letters .

[a-f]

One of the characters in the specified range

[l-r]ower finds "lower," "mower," "power," and "rower," but not words such as "tower" or "cower," which are outside the range. You must specify the range in alphabetical order.

[!a-f]

Any character except those in the specifie-d range

[!l-r]ower finds "bower," "cower," "dower," "tower," and "vower," but not words such as "lower" or "mower," which are inside the range. Again, you must specify the range in alphabetical order.

{n,}

n or more instances of the previous character or expression

ke{1,}p finds "keep," "kepi," and "kept."

{n,m}

From n to m instances of the previous character or expression, where m is 255 or less

5{1,3} finds "5," "55," and "555."

@

One or more instances of the previous character or expression

pe@p finds "pep" and "peep."

\wildcard

Find the specified wildcard

\* finds the * character.


How does this work? You've just used three wildcard characters to build a regular expression. Once you check the "Use wildcards" box in the Find and Replace dialog box, you can use the wildcard characters shown in Table 3-2 to search for items. See the next Annoyance for another example of using wildcards in regular expressions.

You're not going to remember these wildcards, are you? No matter. Check the "Use wildcards" box in the Find and Replace dialog box, and you can click the Special button to display a pop-up menu of the wildcards (see Figure 3-13).

Figure 3-13. Once you've checked the "Use wildcards" box, you can enter wildcards from the Special pop-up menu in the Find and Replace dialog box.

Remove Duplicate Entries from a List

The Annoyance:

So far, so goodthe membership list is now in the format "Membershipnumber Tab Lastname, Firstname," and I've sorted it into ascending order using Table Sort . But I can already see a ton of duplicate entries that Ill need to knock out.

The Fix:

Regular expressions to the rescue again! Choose Edit Replace to display the Find and Replace dialog box. Next, clear any formatting and check the "Use wildcards box. Enter (*^13)(\1)@ in the "Find what" box and \1 in the "Replace with" box. Click the Replace All button. The \1 identifies a recurrence of the previous expressionin this case, any sequence of characters followed by a carriage return (represented by the code ^13 ). The @ makes Word find one or more occurrences of the repeated item. So the expression (*^13)(\1)@ finds a paragraph that is repeated by itself one or more times, and the replacement \1 replaces what is found (the repeated paragraph or paragraphs) with the paragraph itself.



Word Annoyances
Word Annoyances: How to Fix the Most ANNOYING Things about Your Favorite Word Processor
ISBN: 0596009542
EAN: 2147483647
Year: 2003
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net