Solved

Macro to find and highlight any hyphenated words?

Posted on 2012-04-13
3
464 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
Comment Utility
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
Comment Utility
This is awesome, now I won't miss any of those danged hyphens :)
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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 …

771 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

14 Experts available now in Live!

Get 1:1 Help Now