How can I create a macro to find and replace text attributes?

P

pubgal23

Hello, I am working in Word 2003 and am trying to recreate a ton of macros we
had made in WP, one set of them involves finding a text attribute, or finding
and replacing it with something else. I can obviously do this, one by one,
with the find and replace commands...however, for some reason I can't get it
to "stick" in the macro.

Two examples of what I am trying to create would be:

1. Find next bold.

2. Find next underline and change to italics.

anyone have any suggestions?
thanks!
 
J

Jay Freedman

pubgal23 said:
Hello, I am working in Word 2003 and am trying to recreate a ton of
macros we had made in WP, one set of them involves finding a text
attribute, or finding and replacing it with something else. I can
obviously do this, one by one, with the find and replace
commands...however, for some reason I can't get it to "stick" in the
macro.

Two examples of what I am trying to create would be:

1. Find next bold.

2. Find next underline and change to italics.

anyone have any suggestions?
thanks!

I'll guess that you're trying to use the macro recorder to make these
macros. There's a bug in the recorder that prevents it from seeing
formatting changes.

See http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm, in the
section titled "Fixing broken Replace macros", for how to fix the macros
that come from the recorder.
 
P

pubgal23

Thanks! We couldn't figure out if we were doing something wrong, or if there
was a problem in the program...makes us feel better!
thanks for the article, we'll see if we can fix it up!
You've saved our sanity and many hours of wasted work, thanks!
Christina
 
G

Graham Mayor

Thew following provides an example of how formatting changes can be added to
the macro.

Sub ReplaceExample()

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
'**********************
.Text = ""
.Font.Name = "Arial"
.Font.Bold = True
.Font.Size = "12"

.Replacement.Text = ""
.Replacement.Font.Name = "Bookman Old Style"
.Replacement.Font.Size = "11"
.Replacement.Font.Italic = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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