Last active
August 29, 2015 14:09
-
-
Save guyhughes/33f41cb2c9ac2084118f to your computer and use it in GitHub Desktop.
Quick VBA macro to bold keywords.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub BoldKeywords() | |
Dim triggers As Variant | |
' ------------------------------------------ | |
' BEGIN EDIT-ME PART | |
' Help for non-geeks: each item is delimited by a comma, even at the end of a line | |
' each line break inside the array declaration needs an underscore at the end | |
' If you use apostrophes, they must be escaped, e.g. "Canada\'s" | |
' ------------------------------------------ | |
triggers = Array("canada", "canada\'s", _ | |
"#cdnpoli", "#lpc", "Liberal Party of Canada", "Liberal party", _ | |
"Justin Trudeau", "Trudeau", "@JustinTrudeau", "JT" _ | |
) | |
' ------------------------------------------ | |
' END OF EDIT-ME PART | |
' ------------------------------------------ | |
Selection.find.ClearFormatting | |
Selection.find.Replacement.ClearFormatting | |
Selection.find.Replacement.Font.Bold = True | |
For Each trigger In triggers | |
With Selection.find | |
.text = trigger | |
.Replacement.text = "" | |
.Forward = True | |
.Wrap = wdFindContinue | |
.Format = True | |
.MatchCase = False | |
.MatchWholeWord = True 'WHOLE WORD MATHCHING (if off, @CBCCanada would match for 'canada') | |
.MatchWildcards = False | |
.MatchSoundsLike = False | |
.MatchAllWordForms = True | |
End With | |
Selection.find.Execute replace:=wdReplaceAll | |
Next trigger | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment