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: