I am new to writing macros. In Word 2003 I have recorded a macro that Finds
& Replaces the font formatting and size when using wildcards (so that any
string of text between ;;*;; is formatted to Tahoma Bold 12 pt; or any text
between @*@ is formatted to Tahoma Regular 11pt, etc.). As I am recording
the macro, the font style and size is replaced correctly, but when I try to
run the macro in other documents (merged from a database) it just deletes the
text.
What am I doing wrong?
Example:
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\;;*\;;"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\@*\@"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Hi MarS,
The macro recorder didn't record what you want to do with the found text.
The top of your macro should look something like
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Name = "Tahoma"
Selection.Find.Replacement.Font.Bold = True
Selection.Find.Replacement.Font.Size = 12
With Selection.Find
' ...
If you don't specify any replacement formatting, Word takes
.Replacement.Text = ""
literally, and replaces the found text with nothing.
Regards,
Klaus
>I am new to writing macros. In Word 2003 I have recorded a macro that
>Finds
[quoted text clipped - 41 lines]
> .MatchSoundsLike = False
> .MatchWildcards = True
MarS - 11 Mar 2008 13:52 GMT
Thanks, Klaus. I know the macro is not recording any key strokes because I
am selecting formatting changes from pull-down menus, but I'll still give it
a shot. Look out VBA!

Signature
MarS
> Hi MarS,
>
[quoted text clipped - 62 lines]
> > .MatchSoundsLike = False
> > .MatchWildcards = True