Software

Office challenge: How can you force Word to print a letter before its corresponding envelope?

This week, learn the solution to last week's Word sorting challenge and test your skills with a new Word challenge regarding the Envelope feature.

When you add an envelope to a document using Word's Envelopes and Labels feature, Word positions the envelope at the beginning of the document. Most of you will never have a problem with that configuration, but a few printers simply won't comply; you must position the envelope after the document. How would you do this?

Last week we asked:

How would you sort columnar blocks in Word? I even supplied the sample data:

Margaret Peacock

4110 Old Redmond Rd.

Redmond, WA 98052

Nancy Davolio

20th Ave. E.

Apt. 2A

Seattle, WA 98122

Janet Leverling

722 Moss Bay Blvd.

Kirkland, WA 98033

Andrew E. Fuller

908 W. Capital Way

Tacoma, WA 98401

The key to sorting in Word successfully is preparation. Portada provided some great instructions with a solution that's very close to my own. As usual, you all offered great ideas!

Before I offer my solution, I'd like to say a word about training. If you have control over data entry, two habits will help future sorting:

  • Treat each address block as a paragraph. Train users to press [Shift]+[Enter] instead of [Enter] at the end of every line but the last line of each address. Doing so inserts a manual line break. Use [Enter] at the end of the final line of each address block to enter a paragraph mark. Then, each address block, instead of each line, will be a paragraph.
  • Insert a non-breaking space to force Word to ignore middle initials by pressing [Shift]+[Ctrl]+Spacebar.

If you can incorporate the above rules during data entry, the sort task is simple. Unfortunately, you just can't plan away every obstacle, but you can remove them when they show up. To shed a little light, click Show/Hide on the Standard toolbar, to display formatting. In the following figure, a paragraph mark follows each line and two paragraph marks denote each address block by separating each block with a blank line.

With the current configuration, sorting by block is impossible; Word will sort by the first character(s) in each line. That's because Word interprets each line as a paragraph—that's what that paragraph mark means! You must cleanup your data before you can sort and that usually entails one or more Search and Replace tasks.

Cleanup one

The addresses above have a blank line between each address. Using Search and Replace, you can maintain the end of block paragraph mark, while replacing the others with manual line breaks in a three-step process:

  1. Replace the end of block paragraph marks (there's always at least two) with a placeholding character. The character itself doesn't really matter, but choose a character that is not in your data.
  2. Replace all the single paragraph marks with a manual line break (you're replacing each hard return with a soft return).
  3. Replace the placeholding character with a single manual line break (hard return).

Warning: When selecting the sort text, do not include stray paragraph marks before the actual text. Doing so will result in stray blank lines working their way into your sorted block.

Let's apply the above process to the addresses in the above figure:

  1. Select the block of addresses. In this case, be sure to include the second paragraph mark at the end of the last address.
  2. Choose Replace from the Find menu or press [Ctrl]+H. Replace is on the Home tab in the Editing group in Word 2007 and 2010.
  3. In the Find What control, enter ^p^p – that's the carat character ([Shift]+6) and a lowercase p. You need two sets of the code to find two paragraph marks.
  4. In the Replace With control, enter a forward slash or some other special character that isn't in the selected text.
  5. Click Replace All. When prompted, you do not want to search the remainder of the document. The results won't look right to you. The first line of each address is now part of the last line of the previous address. Don't worry—it'll all work out in the end.

The next step is to replace all of the paragraph marks with manual line breaks, as follows:

  1. If the Find and Replace dialog box isn't open, open it by pressing [Ctrl]+H.
  2. In the Find What control, enter ^p.
  3. In the Replace With control, enter ^l—that's a lowercase L and represents a manual line break. Click the Special button and choose it from the resulting list if you don't want to enter it manually.
  4. Click Replace All. Click No when asked to search the remainder of the document. There are no more paragraph marks.

The final step is to replace the placeholder character—I used the / character—with a paragraph mark, as follows:

  1. In the Find What control, enter /.
  2. In the Replace With control, enter ^p.
  3. Click Replace All and then No.
  4. Close the Find and Replace dialog box.

Now, each line of each address, except for the last line, ends with a manual line break (soft return). The last line of each address ends with a paragraph mark (hard return). Word now knows where each address block ends and begins.

You're still not ready to sort because Andrew Fuller's name has a middle initial. If you want to sort by first name, it won't matter, but this lone-wolf initial is a problem if you want to sort by last name. The solution is to replace the space before the middle initial with a non-breaking space. That way, Word will treat the middle initial as part of the first name. This will make more sense later. To create a non-breaking space, represented by the small circle below, press [Ctrl]+[Shift]+Spacebar.

Now, I have to admit that I goofed with this example. Without the non-breaking space, Word sorts this name just fine because the middle initial I added, E, falls just before F, alphabetically. However, if you change that E to a Z and sort the addresses without the non-breaking space, you'll see that Word doesn't sort that block properly. I apologize for the ineffectual initial example!

At this point, you can sort the addresses properly, as follows:

  1. Select the addresses.
  2. Choose Sort from the Table menu. In Word 2007 and 2010, click Sort in the Paragraph group on the Home tab.
  3. Click Options.
  4. Click Other and enter a space character in the Separate Fields At section.
  5. Click OK.
  6. In the Sort By section, choose Word2. Word will sort by the second word, in this case, the last name, not the first.
  7. Choose Text from the Type dropdown (if necessary).
  8. Click OK.

Word is able to sort the addresses by the last names in the first line of each paragraph.

Cleanup two

Sometimes a blank line doesn't separate the blocks. When this is the case, you'll have to find some way to identify that last line. In this case, the Zip Code provides an opportunity to use wildcards in a Search and Replace task.

First, be sure to insert non-breaking spaces between the first name and any middle initials, if necessary. Next, use Search and Replace to insert a placeholder, such as /, after each ZIP code as follows:

  1. Select the addresses.
  2. Press [Ctrl]+H.
  3. In the Find What control, enter the following wildcard string: [0-9]{5}—this will find five consecutive digits.
  4. In the Replace With control, enter the following wildcard string: ^&/—this will replace the found characters with the same characters and a / character. All you're doing is inserting a / character after every occurrence of five digits.
  5. Check the Use Wildcards option.
  6. Click Replace All, or use Find Next and Replace, accordingly. I recommend the latter, because the wildcards in the Find What control will find any set of five digits, not just the Zip Codes. That means, a street address of five digits will match this wildcard configuration.
  7. Click No when prompted to search the remaining document.

Next, replace all the paragraph marks with manual line breaks. In the Find What control, enter ^p. In the Replace With control, enter ^l. Uncheck the Use Wildcards option, and click Replace All.

Your last step is to replace those / characters with paragraph marks, to denote the end of each paragraph. In the Find What control, enter /^l (to replace the / character and the manual line break) in the Replace With control, enter ^p, and click Replace All.

At this point, you're ready to sort, just as you did earlier. Most likely, someone out there has a more efficient process and I'd like to hear about it! I know my solution to this challenge seems complicated, but the key is knowing what Word expects and knowing how to supply that! If this is a frequent issue, create a Word form for data input and do all the formatting behind the scenes.

About Susan Harkins

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

Editor's Picks

Free Newsletters, In your Inbox