Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Macros written to format text between wildcards ends up deleting t

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MarS - 10 Mar 2008 20:52 GMT
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

Signature

MarS

Klaus Linke - 10 Mar 2008 22:28 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.