Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Kay Kay is offline
external usenet poster
 
Posts: 33
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using macros to find and replace Jan Johansson Microsoft Word Help 3 March 3rd 08 01:55 PM
Find & Replace does not find formatting Mike[_7_] Microsoft Word Help 4 August 30th 07 02:39 PM
Find/Replace formatting Mark Microsoft Word Help 2 March 11th 07 06:24 AM
Using find and replace or macros to replace page ranges JeremyC Microsoft Word Help 7 February 13th 06 09:20 PM
Find & Replace does not find formatting Ed Microsoft Word Help 5 April 1st 05 12:33 AM


All times are GMT +1. The time now is 12:06 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"