How to create a macro to format a set of words in Word 2003?

D

Debbie in Plano

I would like to create a macro to thick underline all the coomon helping
verbs in a document. I can do this manually as follows (sorry this is so
wordy ... I wrote it for a friend who doesn't have a techie bone in her body):

Open the “Find and Replace†window (ctrl-H or Edit/Replace).

If the “Less†button is showing, continue to the next step; otherwise,
press the “More†button so that all options are visible.

Complete the window as follows:

Find what:
Type “be†(without the quotes) in the “Find what†text box.

Replace with:
Select the field by clicking the mouse inside the “Replace
with:†text box.

Press the Format button.
Select Font / Underline Style / thick underline … or
whatever formatting you want.

Search:
Checkmark “Find all word formsâ€

Then press the “Replace All†button.

You then have to repeat the replace, substituting the words "have", "do",
"may", "can", "shall", and "will" in the find text box. This procedure will
put a thick underline under all the common helping verbs.

However, if I record these steps as a macro and run the macro, then the
found words are replaced with null (deleted) instead of being underlined.
Here is the macro produced when I did the steps above for the forms of "be":

Sub Mark_Helping_Verbs()
'
' Mark_Helping_Verbs Macro
' Macro recorded 2/13/2008 by HP Authorized Customer
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "be"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Replacement.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


Does anyone know how to fix the macro so that it will underline the found
words instead of deleting them? Or maybe there is a different/better way to
do this?

Thanks,
Debbie
 
P

Patrick Keenan

Debbie in Plano said:
I would like to create a macro to thick underline all the coomon helping
verbs in a document. I can do this manually as follows (sorry this is so
wordy ... I wrote it for a friend who doesn't have a techie bone in her
body):
<snippage>
Does anyone know how to fix the macro so that it will underline the found
words instead of deleting them? Or maybe there is a different/better way
to
do this?

Debbie,
You'll probably have better results asking this in an Office or
Word-specific newsgroup.

But, it looks like you've specified that the replacement text is "", which
pretty much tells the macro to delete the word it found.

You may need to store the word in a variable and specify the variable as the
replacement text.

HTH
-pk
 
D

Debbie in Plano

Figured it out ... adding the following fixes the problem:

.Replacement.Style = True
.Replacement.Font.Underline = wdUnderlineThick
 
D

Debbie in Plano

Aargghh ... only ".Replacement.Font.Underline = wdUnderlineThick" is needed;
the .Replacement.Style will change the paragraph style.

Now I have a happy macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top