Match style

key

Joined
Jun 12, 2022
Messages
2
Reaction score
0
Code:
Sub Testing()

  Dim myDoc As Document

  Set myDoc = ActiveDocument



  Dim rng As Range

  Set rng = myDoc.Content



  Dim findWhat As String

  findWhat = "\<[! ]@\>"



  With rng.Find

    .ClearFormatting

    .Text = findWhat

    .MatchWildcards = True

    .Execute

    Do While .Found

      Dim styleName As String

      styleName = rng.Text



      If myDoc.Styles(styleName).Type = wdStyleTypeParagraph Then

        rng.ParagraphFormat.style = styleName

        rng.Start = rng.Start + 1

        rng.End = rng.End + 1

      Else

        rng.Start = rng.End + 1

        rng.End = rng.End + 1

      End If



      .Execute

    Loop

  End With



  MsgBox "Completed"

End Sub

need to find without angular brackets and replace them in styles if the angular brackets text not match (e.g, <Style1>) skip and replace others in all stories.
 
Last edited:

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