Need a macro to put borders around every occurrence of a word

G

Guest

I want to find several different words in a document, an dhighlight them with
a border (box). I have treid the following section ( with help from the
macro recorder) to do this, but get "Invlaid Use of Propert"y error on the
Borders. how do I appy the border to the found items?

With Selection.Find
.Text = "SYSTEM:"
.Replacement.Text = "SYSTEM:"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.Replacement.Font.Borders (1)
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With


Thanks.
 
J

Jay Freedman

It's not unusual for the macro recorder to botch the job. See
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm.

Here's code that works:

With Selection.Find
.Text = "SYSTEM:"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
Selection.Borders.Enable = True
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

I knew it was simple. I am much better with Excel VBA. This is my first
attempt at Word VBA. You saved me many hours. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top