Retrofitting Styles in MS Word

StylesDo you have any Microsoft Word documents that aren’t taking advantage of styles? Do you want to fix them up fast? Here’s how.

The other day, I was asked to collaborate on enhancing a Microsoft Word document. It’s your typical project planning document. The draft I received already contained three chapters, each with a dozen sections. The first thing I did was insert my “patented” boilerplate introductory chapter, and add my patented boilerplate open-issues chapter to the end. Oops! What’s wrong with this picture?

1 Introduction
1.1 Scope
1.2 Intended Audience
1.3 Glossary of Terms
1.4 Update History

1 - Some Aspect of the Project
1.1 - Some Detail
1.2 - Another Detail
1.3 - And Another Detail
...
1.12 - One Last Detail

2 - Another Aspect of the Project
2.1 - Some Detail
2.2 - Another Detail
2.3 - And Another Detail
...
2.9 - The Ninth Detail

3 - Some Aspect of the Project
3.1 - Some Detail
3.2 - Another Detail
3.3 - And Another Detail
...
3.15 - A 15th Detail

2 Issues
2.1 Open Questions
2.2 Possible Future Enhancements
2.3 Risk Factors

The chapters I inserted have chapter headings and section headings that are formatted according to styles (namely, “Heading 1″ and “Heading 2″, respectively). So, those chapters and sections were numbered automatically for me. The original chapters in the middle, however, did not take advantage of styles. They were all numbered by hand. (Note also that the hand-numbered section titles all happen to have a space-hyphen-space between the number and the text.) Well, no worries. We’ll have it all fixed up in a jiffy.

In Quick Tip: Using MS Word’s Search & Replace on Formatting, I showed how the search and replace function in Microsoft Word works to change formatting, and not just text. We are going to use it here to apply the Heading styles we need.

Bullets and NumberingIf you care to follow along, open up a new word document and paste into it the text above, starting with “1 - Some Aspect Of The Project”, and ending with “3.15 - A 15th Detail”. Also, be sure that outline numbering is turned on. Pull down the Format menu, and select “Bullets and Numbering…”. Then click on the Outline Numbered tab, and select an appropriate layout.

For this technique, the first thing we need to do is come up with a random sequence of characters that does not currently appear in the document. I typically use three tilde characters (~~~). The document might, possibly, have one tilde somewhere, but it’s very unlikely to have three in a row. Just to be safe, bring up the Find dialogue (Ctrl+F), and search for “~~~”. If you do find such an occurrence, then pick another sequence and try again. We will be using this sequence of characters as a “placeholder.” Now, we are ready to get started.

Section Headings - Heading 2 Style:
Find and Replace
First up, we’ll change the section headings to Heading 2 style. For this technique, it’s important to work from the inside out, starting with the deepest heading level. (I will explain why at the end.)

  1. Highlight the section of text to be affected (if not the whole document).
  2. Bring up the search and replace tool (Ctrl+H).
  3. Click on the More button to reveal the formatting options.
  4. Click in the Find What box, so that it has focus (there should be a flashing cursor there).
  5. Click on the Special button, and select Any Digit. This will insert a “^#” for you.
  6. After the number sign, type in a period, another ^#, a space, a hyphen, and another space.
  7. Click in the Replace With box, so that it has focus (there should be a flashing cursor there).
  8. Type in three tilde characters (~~~), or whatever placeholder we decided to use, above.
  9. Click on the Format button, and select Style.
  10. Press the letter H, to jump down to the styles that begin with H, and then press the down-arrow key until you get to “Heading 2″. Click OK.
  11. Click the Replace All button.

Why the Placeholder?: You’re probably wondering, “Why do we need the three tildes?” One problem with using the find and replace tool to make formatting changes is that if we were to leave the Replace-With box empty yet specify a replacement format (in this case “Heading 2″), then Microsoft Word assumes we do not want to change the found text — that we only want to apply the formatting. But, here we do want to replace the found text, the numbers and hyphens. We want to replace them with nothing, because the heading style will automatically supply the appropriate new numbers. So, as an intermediate step we will temporarily replace the numbers and hyphens with our three-tilde placeholder. Later, we’ll do another search and replace (without any formatting constraints) and get rid of the tildes.

Repeat for the Double-Digit Sections: At this point, all of the section headings that were numbered with a single second digit (e.g. 1.1 thru 1.9) should now begin with three tildes and be formatted with the Heading 2 style. (Section numbers may or may not appear, depending on whether or not we’ve told Word to turn on outline numbering yet.) If there are any chapters that contain more than nine sections, however, than those double-digit sections (1.10+) will not have been fixed up yet. This is because we told Word to only look for one digit (^#). So, all we have to do now is

  1. Bring up the Find and Replace dialog again (Ctrl+H). The previous values should all still be present.
  2. Click in the Find What box, after the second ^# and add another ^#, making it “^#.^#^# - “.
  3. Click the Replace All button.

Chapter Headings - Heading 1 Style: Now, we need to do the chapter headings.

  1. Bring up the Find and Replace dialog again (Ctrl+H). The previous values should all still be present.
  2. Click in the Find What box, and delete the leading ^#.^#, making it “^# - “.
  3. Click in the Replace With box.
  4. Click on the Format button, and select Style. It should default to “Heading 2″.
  5. Press the up-arrow key to get to “Heading 1″. Click OK.
  6. Click the Replace All button.

Remove the Placeholders: Finally, we just have to get rid of the tilde placeholders.

  1. Bring up the Find and Replace dialog again (Ctrl+H). The previous values should all still be present.
  2. Click in the Find What box, and change it to three tildes (~~~).
  3. Click in the Replace With box and delete the three tildes that are there.
  4. Click on the No Formatting button.
  5. Click the Replace All button.

Wallah!

A Variation: I made this example easy by supposing that a space-hyphen-space existed between the handwritten numbers and the section headings, so we were able to latch onto that as part of the search criteria, relying on the fact that it is unlikely such a sequence (digit-space-hyphen-space) would occur anywhere else in the document other than in the section heading. If such hyphens are not present, e.g. just “1 Some Aspect of the Project” rather than “1 - Some Aspect of the Project”, then the task is much harder. After all, we wouldn’t want to turn every paragraph that happens to contain a digit in it somewhere into a section heading. There are some fancy ways to deal with this that involve counting on the fact that only section headings are likely to have a digit as the first character of the line (paragraph), by latching on to the paragraph break (^p). However, they are not straightforward. (If you are not careful, the heading to style gets applied to the paragraph above the section header, rather than the section header itself.) So, my best advice is to manually insert a space-hyphen-space into each section heading line that needs to be changed (or, better yet, some other unique sequence of characters that is guaranteed not to exist anywhere else in the document), and then perform this technique. It should only take a minute or two to whip through the document and paste in those sequences (Ctrl+V), which is still much faster than setting all of the styles by hand.

Related articles:

Post a Comment


Your email is never published nor shared. Required fields are marked *



© 2006-2007 Maxim Software Corp.  All rights reserved.