Share via

Macro for formatting heading styles

Anonymous
2013-01-16T02:10:58+00:00

I'm working with a template that uses character styles for bold and italics. I need a macro that finds all instances of bold or italics that were applied as direct formatting (ie Ctrl+I, Ctrl+B) and replaces them with the correct character style. However, simply searching for bold or italic font and replacing it with the style also changes the formatting in all the headings that are bold or italic (although they retain their paragraph styles). So after I've changed the bold and italics to character styles, I need a way to find all instances of Heading 1, Heading 2 etc, clear the character style formatting and reapply the correct heading paragraph style. Or, a way of applying the character styles for bold and italics everywhere EXCEPT headings. I need to do this across the entire document.

I'd really appreciate any suggestions!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2013-01-16T02:34:15+00:00

Try the following, inserting the name of your required style in place of [bold style]:

Selection.HomeKey wdStory

Selection.Find.Font.Bold = True

With Selection.Find

    Do While .Execute(FindText:="", Forward:=True, _

    MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=True) = True

        If Left(Selection.Style, 7) <> "Heading" Then

            Selection.Style = "[bold style]"

            Selection.Collapse wdCollapseEnd

        End If

    Loop

End With

and the same code with appropriate substitutions for Italic

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-01-16T02:51:55+00:00

    Perfect - thanks Doug!

    Was this answer helpful?

    0 comments No comments