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 / September 2006

Tip: Looking for answers? Try searching our database.

Word macro doesn't remember colors!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joy - 06 Sep 2006 20:51 GMT
What am I doing wrong? Word 2003 on XP SP2.

I want a macro to change all occurances of Piano to be shown in bold and  
red. I recorded the macro and it worked at that time. But using the macro  
does not work. You can see that the replacement information such as bold  
and color is not recorded.

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "Piano"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

I tried

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "Piano"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    With Selection.Find.Replacement
        .Text = "\1"
        .Font.Color = wdBlue
        .Font.Bold = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

but that didn't work either.

Why does Word not record this correctly and how can I fix it?

Thank you!

Joy
Jay Freedman - 07 Sep 2006 03:54 GMT
See http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm,
especially the section "Fixing broken Replace macros".

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>What am I doing wrong? Word 2003 on XP SP2.
>
[quoted text clipped - 49 lines]
>
>Joy
 
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.