Replacing and Formatting at the Same Time

by Allen Wyatt
(last updated August 22, 2015)

8

Patrick has a document in which there are "start" and "stop" character sequences that indicate where italics should begin and end. For instance, in the text sequence "$$$This is some text!$!" the "$$$" indicates the start of italics and the "!$!" indicates the end. Patrick wonders if there is a way he can use Find and Replace to (1) remove the character sequences and (2) format the text between those character sequences to italics.

This type of Find and Replace may sound difficult, but Word actually makes it quite easy, provided you use wildcards in your F&R operation. Follow these steps:

  1. Press Ctrl+H to display the Replace tab of the Find and Replace dialog box.
  2. Click the More button, if it is visible.
  3. Make sure the Use Wildcards check box is selected.
  4. In the Find What box, enter "$$$(*)\!$\!" (without the quote marks).
  5. In the Replace With box, enter " \1" (again, without the quote marks).
  6. With the insertion point still in the Replace With box, press Ctrl+i. (This tells Word that you want the replacement text to be formatted as italics.)
  7. Click on Replace All.
  8. Close the Find and Replace dialog box.

That's it; only a single find-and-replace operation is needed. The "find" pattern (in step 4) indicates you want to find anything (*) surrounded by your indicated markers. Note that the backslashes before the exclamation marks in step 4 are important, as they cause the characters to be treated as actual exclamation marks.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3851) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Editing AutoCorrect ACL Files

Information used with the AutoCorrect feature is stored in what is known as an ACL file. You normally edit this file by using ...

Discover More

Reusing a Bookmark

Bookmarks in Word are just like bookmarks used in paper books, any given bookmark may be reused to mark a new location. ...

Discover More

Turning Off Word's Second Guessing with Quote Marks

When you type quote marks in a document, Word normally changes them to Smart Quotes. They look better on a printout, but Word ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE WORDTIPS (RIBBON)

Special Characters in Pattern Matching

The most powerful search engine in Word use pattern matching, but the way you specify special characters in a ...

Discover More

Matching At the Beginning or End of a Word

The pattern matching capabilities of Word's search engine are quite powerful. You can tailor your search pattern so that ...

Discover More

Replacing Text and Capitalizing a Letter in One Step

The Find and Replace capabilities of Word are very powerful. You can even use them to do some complex and specific searching ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 9?

2015-08-29 08:48:48

Ken Endacott

Jim
The following code will change the spacing of just the one paragraph. Place the cursor anywhere in the paragraph and run the macro. Note that if the paragraph has its style re-applied then the spacings will revert to those of the style.

With Selection.Paragraphs(1).Range.ParagraphFormat
.LineSpacingRule = wdLineSpaceSingle
.SpaceAfter = 0
.SpaceBefore = 0
End With

The following code will change the spacing of the selected paragraph's style so that all paragraphs that use the style will have their spacing changed.

With ActiveDocument.Styles(Selection.Paragraphs(1).Style).ParagraphFormat
.LineSpacingRule = wdLineSpaceSingle
.SpaceAfter = 0
.SpaceBefore = 0
End With


2015-08-28 07:33:06

Jim Andrews

Phil Reinie,
That is what I'm trying to eliminate; the 6 points of white space before and after a paragraph using a macro.
Recording the process does not do the trick.
I am familiar with editing macros, but can't figure out what to place in the macro to accomplish this.

Thanks to everyone who replied.
Jim


2015-08-27 10:09:17

Phil Reinie

gbjim.andrews

Is the space above the paragraph its own paragraph or does the paragraph you with "space before" just greater space than you want?

KenE basically covered the first one:
where you are replacing paragraphs with only "white space" (no text) with no paragraph (IE, replace something with nothing (essentially delete the no-text paragraph)), ...

and in the second you can change the style of the paragraph to have zero (or whatever) points of space you want (before or after, or both) for the paragraph.

Body text paragraph style has 6 points of spacing after each paragraph, but Normal paragraph has zero point of spacing after. (They both have zero points before the paragraph.) So you could also select all paragraphs of one type (style) and change them to a different style.


2015-08-23 21:02:12

awyatt

Peter: Step 5 tells Word to use, as replacement text, the first (1) occurrence of text within parentheses from the "Find What" text.

Thus, the 1 results in whatever is matched by the asterisk (*) in the "Find What" text.

-Allen


2015-08-23 15:31:09

Peter Kirkpatrick

This is described as an easy process, but not to me! Can someone explain to me what Step 5 does?


2015-08-23 05:39:44

Ken Endacott

The easiest way to create your macro is to use Record Macro then run Find and Replace with the three Find and Replace string pairs. The three macros can then be combined into one. The strings are:

Change multiple spaces to one space:
[^32]{2,}
^32"

Remove blank paragraphs
[^13]{2,}
^p

Remove all spaces at end of paragraph:
^32{1,}^13
^p

Don't forget to turn on Use Wildcards.


2015-08-22 08:24:18

gbjim.andrews

Great!
I've been trying to use macro to:
1. set all to single space
2. remove space above paragraph
3. remove space after paragraph

All to no avail.
Any ideas?


2015-08-22 07:27:48

Rod Grealish

This technique could be used with simple embedded HTML tag pairs such as <I> </I>, <B> </B> or <H1> </H1>. A document prepared with a basic editor could be opened in Word and the tags replaced by the appropriate formatting. In step 6 of the tip replace the shortcut (Ctrl+i) by another formatting shortcut. For more complex formatting click on the Format button, Click Font ... option and select the required combination of formatting such as Font, Font style, Font size, Underline.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing