Solved

Macro to find and highlight any hyphenated words?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
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…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

806 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