I’m relatively new to VBA programming, but not to programming in general. I have a series of quotes stored in single column table rows in Word (365, Version 2403, Build 16.0) and need to adjust the formatting of the quote attribution. The format of each quote/row is:
This is a quote.
- Attribution Name
This is a quote. - Attribution
This is a quote. - Attribution123
where the Attribution may be 1 or 2 words of alphanumeric characters. I need to format all characters after the “- “. Currently, my attempts only format up until the space after the first word, regardless of any space characters included in the RegEx format search. It works perfectly on single name attributions.
After searching the web and other posts, here is my current macro:
Sub DashFormat()
'
' DashFormat Macro
'
'
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Format = True
.Wrap = wdFindContinue
.MatchWildcards = True
.MatchWholeWord = False
.Text = "- [A-z0-9]@>"
.Replacement.Style = "Subtle Emphasis"
.Execute Replace:=wdReplaceAll
End With
End Sub
Referencing the above example, this correctly applies the style to everything after the – except ” Name”.
I understand all of this EXCEPT the function of @> at the end of the .Text string. I know that it doesn’t work without the addition of some character specification in brackets before it.
I have tried adding a space in the brackets, I’ve tried indicating space Chr codes, I’ve played around with wildcards and escape characters. Can anyone help me design the query or explain the function of @>?
Kathryn Hunter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.