View Single Post
 
Old 07-25-2019, 02:41 PM
WVA WVA is offline Windows 10 Office 2016
Novice
 
Join Date: Jul 2019
Posts: 4
WVA is on a distinguished road
Default Macro to apply a style between quotations

I am trying to create a macro that applies a style to words between quotation marks. The macro should only work for words that are capitalized as well. For example "Definition" would get the style applied to it, but "definition" wouldn't. I've gotten a find and replace to work but only for the first example in a document. I'd like the macro to loop through the entire document. Any help would be greatly appreciated.

Thanks,

Sub Demo()

Selection.HomeKey Unit:=wdStory

With Selection.Find
.ClearFormatting
.Text = "[^0147][A-Z]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' switch on selection extend mode
Selection.Extend

With Selection.Find
.ClearFormatting
.Text = "[^0148]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute

If Selection.Find.Found Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Style = ActiveDocument.Styles("Defined Terms Char")
End If
End With
End If
End Sub
Reply With Quote