VB-AN-IZ
10-24-2017, 12:35 AM
Related to:
http://www.vbaexpress.com/forum/showthread.php?57443-Highlight-All-Words-Containing-Capital-Letters
This code will highlight any words which contain a capital letter:
Sub highlight_capitals()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(findtext:="( [A-Z]*>)", MatchWildcards:=True)
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
End Sub
Note that it highlights not just the words containing capital letters, but also the spaces between any consecutive words that contain capital letters. So, "United States" would be highlighted; not "United" and "States" separately.
I'm hoping to expand it by being able to specify common phrases like "of the", or a hyphen, so that they are also highlighted when they occur between words which contain capital letters.
For example:
Currently, for "State of the Nation", only "State" and "Nation" are highlighted.
Currently, for "World Anti-Doping Code", only "World Anti" and "Code" are highlighted.
Hope that makes sense, and thanks for any help!
http://www.vbaexpress.com/forum/showthread.php?57443-Highlight-All-Words-Containing-Capital-Letters
This code will highlight any words which contain a capital letter:
Sub highlight_capitals()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(findtext:="( [A-Z]*>)", MatchWildcards:=True)
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
End Sub
Note that it highlights not just the words containing capital letters, but also the spaces between any consecutive words that contain capital letters. So, "United States" would be highlighted; not "United" and "States" separately.
I'm hoping to expand it by being able to specify common phrases like "of the", or a hyphen, so that they are also highlighted when they occur between words which contain capital letters.
For example:
Currently, for "State of the Nation", only "State" and "Nation" are highlighted.
Currently, for "World Anti-Doping Code", only "World Anti" and "Code" are highlighted.
Hope that makes sense, and thanks for any help!