I often get documents that have had the heading styles
manually formatted so that when I drop portions of the
document into my template these headings don't update
properly. I would like to create a macro to loop through
the headings and reapply the heading style to eliminate
any manual formatting.
Here is my attempt. I get an error in the first line
because I don't know how to properly declare which element
in which collection to loop through, and I don't know how
to find out.
Sub UpdateHeaders()
For Each HeadingStyles In ActiveDocument
If Selection.Style = ActiveDocument.Styles("Heading 1")
Then
With Selection
.Paragraphs(1).Range.Select
.Collapse Direction:=wdCollapseStart
.Style = ActiveDocument.Styles("Heading 1")
End With
ElseIf Selection.Style = ActiveDocument.Styles("Heading
2") Then
Selection.Style = ActiveDocument.Styles("Heading 2")
ElseIf Selection.Style = ActiveDocument.Styles("Heading
3") Then
Selection.Style = ActiveDocument.Styles("Heading 3")
ElseIf Selection.Style = ActiveDocument.Styles("Heading
4") Then
Selection.Style = ActiveDocument.Styles("Heading 4")
End If
Next HeadingStyles
End Sub
Thanks for any help,
Blake