Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Macro to find and highlight any hyphenated words?

Posted on 2012-04-13
3
Medium Priority
?
546 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

783 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