Find and highlight all instances of ALL CAPS

I

ISay

I know, thanks to y'all, that <[A-Z]{2,}> will find words written in ALL
CAPS. How can I find and highlight all instances?

Is there a way to get it to recognize whole words and not instances like FBI
or CIA?

When I have searched for words and then marked them to be highlighted, when
I exit the FIND window, the highlighting disappears. I know I'm not doing
something right but I don't know what.
 
G

Greg Maxey

USay,

AFAIK there isn't a complete solution. You can certainly find and highlight
all instances ALL CAP words. With a macro, you can even exclude the
specific acronyms FBI and CIA, however excluding "like" acronyms is a
different matter:

Sub SratchMacro()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "<[A-Z]{2,}>"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
Select Case .Text
Case "FBI", "CIA" 'add as many acronyms as necessary.
'Do Nothing
Case Else
.HighlightColorIndex = wdYellow
End Select
End With
Loop
End With
End Sub

For help installing macros see:

http://www.gmayor.com/installing_macro.htm

Note the macro above only searches the current document story range (range
containing the cursor). If you need to search all story ranges (e.g.,
headers, footers, etc.) then it would require more code.


I know, thanks to y'all, that <[A-Z]{2,}> will find words written in
ALL CAPS. How can I find and highlight all instances?

Is there a way to get it to recognize whole words and not instances
like FBI or CIA?

When I have searched for words and then marked them to be
highlighted, when I exit the FIND window, the highlighting
disappears. I know I'm not doing something right but I don't know
what.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
 
G

Graham Mayor

If the words are formatted with the All Caps font parameter then you would
need a slightly different approach

Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = ""
.Font.AllCaps = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
Select Case .Text
Case "FBI", "CIA" 'add as many acronyms as necessary.
'Do Nothing
Case Else
.HighlightColorIndex = wdYellow
End Select
End With
Loop
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg said:
USay,

AFAIK there isn't a complete solution. You can certainly find and
highlight all instances ALL CAP words. With a macro, you can even
exclude the specific acronyms FBI and CIA, however excluding "like"
acronyms is a different matter:

Sub SratchMacro()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "<[A-Z]{2,}>"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
Select Case .Text
Case "FBI", "CIA" 'add as many acronyms as necessary.
'Do Nothing
Case Else
.HighlightColorIndex = wdYellow
End Select
End With
Loop
End With
End Sub

For help installing macros see:

http://www.gmayor.com/installing_macro.htm

Note the macro above only searches the current document story range
(range containing the cursor). If you need to search all story
ranges (e.g., headers, footers, etc.) then it would require more code.


I know, thanks to y'all, that <[A-Z]{2,}> will find words written in
ALL CAPS. How can I find and highlight all instances?

Is there a way to get it to recognize whole words and not instances
like FBI or CIA?

When I have searched for words and then marked them to be
highlighted, when I exit the FIND window, the highlighting
disappears. I know I'm not doing something right but I don't know
what.
 
G

Greg Maxey

Graham,

Roger that. Good point. Thanks.

Graham said:
If the words are formatted with the All Caps font parameter then you
would need a slightly different approach

Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = ""
.Font.AllCaps = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
Select Case .Text
Case "FBI", "CIA" 'add as many acronyms as necessary.
'Do Nothing
Case Else
.HighlightColorIndex = wdYellow
End Select
End With
Loop
End With



Greg said:
USay,

AFAIK there isn't a complete solution. You can certainly find and
highlight all instances ALL CAP words. With a macro, you can even
exclude the specific acronyms FBI and CIA, however excluding "like"
acronyms is a different matter:

Sub SratchMacro()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "<[A-Z]{2,}>"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
Select Case .Text
Case "FBI", "CIA" 'add as many acronyms as necessary.
'Do Nothing
Case Else
.HighlightColorIndex = wdYellow
End Select
End With
Loop
End With
End Sub

For help installing macros see:

http://www.gmayor.com/installing_macro.htm

Note the macro above only searches the current document story range
(range containing the cursor). If you need to search all story
ranges (e.g., headers, footers, etc.) then it would require more
code. ISay said:
I know, thanks to y'all, that <[A-Z]{2,}> will find words written in
ALL CAPS. How can I find and highlight all instances?

Is there a way to get it to recognize whole words and not instances
like FBI or CIA?

When I have searched for words and then marked them to be
highlighted, when I exit the FIND window, the highlighting
disappears. I know I'm not doing something right but I don't know
what.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
 
L

Lene Fredborg

You do not need to leave the Find and Replace dialog box in order to apply
the highlight. Insert whatever you want to search for in the "Find what"
field. Click in the "Replace with" field. Then select Highlight from the
Format menu (bottom of dialog box - click More if it is not visible) and
leave the Replace with field empty. When you click Replace All, the
currently selected highlight color will be applied to all instances found.
This also works with wildcard search.


--
Best regards
Lene Fredborg
Microsoft MVP (Word)
DocTools - Denmark
http://www.thedoctools.com


Pamelia Caswell via OfficeKB.com said:
If using W2007: after setting up your search, click the find in button and
choose "Main Document". Word will select all instances. Without closing
the
Find dialog, change the focus to the document and then click the highlight
icon (home tab > font group). All the selected items will be highlighted.
You can also use the reading highlight, but I prefer to select the items
because you can act on the selections (highlight, copy, paste, change
font,
delete, etc.).

If using W2003: after setting up your search, put a check in the box
before
"Highlight all items found in:" and then click find all. Without closing
the Find dialog, change the focus to the document and then click the
highlight icon (home tab > font group). All the selected items will be
highlighted.

Pam
I know, thanks to y'all, that <[A-Z]{2,}> will find words written in ALL
CAPS. How can I find and highlight all instances?

Is there a way to get it to recognize whole words and not instances like
FBI
or CIA?

When I have searched for words and then marked them to be highlighted,
when
I exit the FIND window, the highlighting disappears. I know I'm not doing
something right but I don't know what.
 
L

Lene Fredborg

Something has been wrong in the Microsoft Discussion Groups for some time.
There is a delay in showing replies posted from elsewhere (sometimes for days
and maybe some replies never appear). Currently, 5 replies have been given to
your question(s) but I can see that none of them appear in the Microsoft
Discussion Groups yet. The thread can be read here:

http://groups.google.com/group/micr...ks+to+y'all,+that+<[A-Z]{2,}>+will+find+words

Hopefully, the problem with the delay will be fixed soon.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
I

ISay

Thanks, following your link I was able to find the solution.

I didn't think to go outside the window to highlight text before closing it.
With this solution I can create a more simple Macro for what I want.
 
S

Suzanne S. Barnhill

As Lene points out, however, it is not necessary to leave the Replace dialog
to apply the highlight, as this can be made part of the search by selecting
Format | Highlight in the "Replace with" box.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top