Solved

Macro to find and highlight any hyphenated words?

Posted on 2012-04-13
3
492 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
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:
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

756 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