View Full Version : [SOLVED:] Highlight All Words Containing Capital Letters?
VB-AN-IZ
10-16-2016, 08:35 AM
Plagiarizing from this macro:
http://www.vbaexpress.com/forum/showthread.php?56757-Question-on-highlighting-word-before-amp-after-quot-and-quot
...I came up with this, which could probably be finessed, but does the basic job:
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
Pedantically, is it possible to avoid highlighting the next punctuation symbol and/or space?
Thanks for any help!
gmaxey
10-16-2016, 03:33 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
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
lbl_Exit:
Exit Sub
End Sub
VB-AN-IZ
10-18-2016, 06:05 AM
Amazing. Thank you!
Programmer_n
02-22-2017, 06:28 PM
How to avoid the first word of the paragraph and the capital word succeeding sentence terminal (.!?), if the intention is only to find capital word caught between words?
So there seems to be two issues?
1. The capital word at the start of the paragraph
2. The capital word that follows a punctuation and space
A round-about way of achieving the result adapted from Greg Maxey code.
Sub Highlight_capital()
'Adapted from - A basic Word macro coded by Greg Maxey
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
Dim oRng1 As Range
Set oRng1 = ActiveDocument.Range
With oRng1.Find
Do While .Execute(FindText:="([.\!?]) [A-Z]*>", MatchWildcards:=True)
oRng1.HighlightColorIndex = wdNoHighlight
oRng1.Collapse 0
Loop
End With
End Sub
Issues.
If you plan to extract unique words, then noun clusters can pose a problem. (As in Output: Made it bold instead of highlight)
Output
To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can always restore the look of your document to the original contained in your current template.
Is there an elegant solution?
VB-AN-IZ
05-09-2017, 08:25 PM
Belated thanks for an excellent addition. (Sadly inevitable) pedantic follow-up – is it possible to also...
1) Un-highlight the space/punctuation preceding the first highlighted word?
2) Highlight the first word of a sentence if the second word is highlighted?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.