Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and Replace Macros for formatting
Hello all,
Our goal is to find any text with formatting of Arial, bold Italic and 14 pts and replace that with a Heading 2 Style. If you record the macro the steps work, but nothing happens when you play back the macro on another document. My code is below. Sub Macro1() ' ' Macro1 Macro ' Macro recorded 5/21/2008 by Genzyme Corporation ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 2") Selection.Find.Replacement.ParagraphFormat.Borders .Shadow = False With Selection.Find .Text = "" .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 End Sub YOur help will be appreciated. |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and Replace Macros for formatting
There is a bug in the macro recorder for all versions except Word 2007. It
records ".Format = True" but fails to record any of the formatting instructions that should accompany it. See http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm for an explanation of how to insert the necessary instructions. You'll need .Font.Name = "Arial" .Font.Bold = True .Font.Italic = True .Font.Size = 14 -- 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. Kay wrote: Hello all, Our goal is to find any text with formatting of Arial, bold Italic and 14 pts and replace that with a Heading 2 Style. If you record the macro the steps work, but nothing happens when you play back the macro on another document. My code is below. Sub Macro1() ' ' Macro1 Macro ' Macro recorded 5/21/2008 by Genzyme Corporation ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 2") Selection.Find.Replacement.ParagraphFormat.Borders .Shadow = False With Selection.Find .Text = "" .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 End Sub YOur help will be appreciated. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Using macros to find and replace | Microsoft Word Help | |||
Find & Replace does not find formatting | Microsoft Word Help | |||
Find/Replace formatting | Microsoft Word Help | |||
Using find and replace or macros to replace page ranges | Microsoft Word Help | |||
Find & Replace does not find formatting | Microsoft Word Help |