Find Highlighted Text

E

Eric White

I am trying to write code that will find and record (into a collection) all
highlighted words/phrases within a document, but I've yet to comprehend
Word's Find Method. Does anyone have anything similar? Or have a link to a
GOOD (i.e., not like the one in the Help Files) explanation of the Find
Method?

-EW
 
H

Helmut Weber

Hi Eric,

maybe like this:

Sub test6456()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = ""
.Highlight = True
If .Execute Then
rDcm.Select 'for testing, do what you like with it
End If
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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