Replace Style Macro

C

Cissy

Hi and thanks for your help. I'm using Word XP, I have a macro that will
replace a set of home-grown numbering styles with the Heading styles. It
works great! Except when one of the styles I'm replacing has formatting
applied on top of the style, then it does not replace it.

So far I have:

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("IRWL1_L1")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 1")

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

As soon as it comes across "IRWL1_L1" with some underlining, it fails. How
can I rewrite this to catch all incidents of the IRWL1_L1 style even if it
has direct formatting? Thanks much!
 
K

Klaus Linke

Hi Cissy,

You're sure it's really underlining and not Track Changes?
Manual underlining shouldn't matter at all if you search for some style.

Regards,
Klaus
 
C

Cissy

Thank you Chuck and Klaus. I did make this work by removing the .format =
true line altogether - it seems that when I changed it to false it wouldn't
change the style at all. I would not have figured this out without your
help. Thanks much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top