Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find and highlight all instances of ALL CAPS

30 views
Skip to first unread message

ISay

unread,
Nov 7, 2009, 8:02:02 AM11/7/09
to
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

unread,
Nov 7, 2009, 8:22:41 AM11/7/09
to

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.

--
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)

Graham Mayor

unread,
Nov 7, 2009, 8:41:36 AM11/7/09
to
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
Word MVP web site http://word.mvps.org

Greg Maxey

unread,
Nov 7, 2009, 9:05:57 AM11/7/09
to
Graham,

Roger that. Good point. Thanks.

Graham Mayor wrote:
> 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
>
>
>

--

Pamelia Caswell via OfficeKB.com

unread,
Nov 7, 2009, 12:57:20 PM11/7/09
to
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

--
Message posted via http://www.officekb.com

Lene Fredborg

unread,
Nov 7, 2009, 6:48:15 PM11/7/09
to
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" <u43222@uwe> skrev i en meddelelse
news:9ec4df4996dee@uwe...

Lene Fredborg

unread,
Nov 7, 2009, 7:22:01 PM11/7/09
to

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/microsoft.public.word.docmanagement/browse_thread/thread/dbb0028e26b2af15/d4321ba24f942a01?q=I+know,+thanks+to+y%27all,+that+%3C%5BA-Z%5D%7B2,%7D%3E+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

ISay

unread,
Nov 8, 2009, 1:31:02 AM11/8/09
to

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.

Suzanne S. Barnhill

unread,
Nov 8, 2009, 8:00:24 AM11/8/09
to

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

"ISay" <IS...@discussions.microsoft.com> wrote in message
news:0992E161-9ADD-41FC...@microsoft.com...

0 new messages