Solved

Macro to find and highlight any hyphenated words?

Posted on 2012-04-13
3
465 Views
Last Modified: 2012-06-27
Hello, I would like to search through a word document and highlight any words with a hyphen.  

For example:

My favorite tech site is experts-exchange.  

I would like the macro to highlight 'experts-exchange'.  Does anyone know how to do this?

Thank you,
Bev
0
Comment
Question by:Bevos
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37842991
You can do the in one Find and Replace step without a macro. However here is some VBA to do the job.
Sub HiHyphWords()
    With ActiveDocument.Range.Find
        .MatchWildcards = True
        .Text = "<[A-z]{1,}-[A-z]{1,}>"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window

0
 

Author Closing Comment

by:Bevos
ID: 37844134
This is awesome, now I won't miss any of those danged hyphens :)
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37844455
I have refrained from a point-by-point explanation, but for this string "<[A-z]{1,}-[A-z]{1,}>",  the equivalents are:

 <              word start
[A-z]{1,}     one or more letters
>               word end

A full exposition of Wildcarding can be found here:

http://word.mvps.org/FAQs/General/UsingWildcards.htm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now