Find / Replace styles

J

JSM

Hi,

Is there a quicker way of finding text formatted with StyleA (paragraph
style) and reformatting it with StyleB (using VBA) than cycling through each
paragraph and modifying the attached style name accordingly? I don't want to
modify StyleA as I still need it in other documents.

Cheers,

John
 
P

Peter Hewett

Hi JSM

Try something like this:

Sub FindAndReplaceStyles()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles("StyleA")
.Replacement.ClearFormatting
.Replacement.Style = ActiveDocument.Styles("StyleB")
.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

It will do what you want.

HTH + Cheers - Peter
 
S

SandyB

You don't need VBA at all.

Use the standard Find and Replace dialog box. Click the More button, then the Format button and choose Style (your cursor should be in the Find What box).
Repeat the Style selection with your cursorin the Replace with box.
Click Replace or Replace All.


----- JSM wrote: -----

Hi,

Is there a quicker way of finding text formatted with StyleA (paragraph
style) and reformatting it with StyleB (using VBA) than cycling through each
paragraph and modifying the attached style name accordingly? I don't want to
modify StyleA as I still need it in other documents.

Cheers,

John
 
J

JSM

Thanks for your reply. I needed it in VBA because I need to do this over
several hundred documents.

Cheers,

John

SandyB said:
You don't need VBA at all.

Use the standard Find and Replace dialog box. Click the More button, then
the Format button and choose Style (your cursor should be in the Find What
box).
 

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