Conditional Find and Replace Styles
Hi
I have written code that goes through a long document and replaces one set of styles with another. I am using Find and Replace and it works OK, but I am stuck with a conditional bit that goes like this:
When it finds Heading 3, if the preceding paragraph style is Heading 1 or Body text, replace Heading 3 with Heading 2 (otherwise leave it)
This is the straightforward replacement, but it needs the conditional bit (I guess it needs a loop, but I just can't get it right)
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("Heading 3")
.Text = ""
.Replacement.Style = ActiveDocument.Styles("Heading 2")
.Execute Replace:=wdReplaceAll
End With
|