D
DA
Hi William
There are a few different ways you could do this, but
here's one example on how you can do your highlighting.
I've used a document called "Keywords.doc", which
contains single word paragraphs for each of the search
terms. Note that you'll have to change file and path info
to suit your setup.
Paste this code into the document where you want to do
your highlighting. Look at the code comments, but it's
fairly basic, so I hope you can follow it without any
problems.
The routine fills an array from the keywords doc and then
uses that data in a simple find/replace.
Hope that helps,
Dennis
---------------
Sub ShowMyWords()
Dim lngCounter As Long
Dim strText As String
Dim astrSearchTerms() As String
'Open your keywords document
Documents.Open FileName:="c:\tmp\keywords.doc"
'Size an array to the number of terms
lngParaCount = ActiveDocument.Paragraphs.Count
ReDim astrSearchTerms(lngParaCount - 1)
'Fill the array with the search terms
For lngCounter = 1 To lngParaCount
strText = ActiveDocument.Paragraphs(lngCounter). _
Range.Text
astrSearchTerms(lngCounter - 1) = _
Left(strText, Len(strText) - 1)
Next
'Close your keywords document
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Highlight the search terms in the active document.
lngCounter = 0
While astrSearchTerms(lngCounter) <> ""
With ActiveDocument.Content.Find
.Wrap = wdFindAsk
.Replacement.Highlight = True
.Execute FindText:=astrSearchTerms(lngCounter), _
ReplaceWith:="", Replace:=wdReplaceAll, _
Forward:=True
End With
lngCounter = lngCounter + 1
Wend
End Sub
---------------
mark them (make selection?), and to highlight the matched
words wt colors.
highlight them if necessary?
There are a few different ways you could do this, but
here's one example on how you can do your highlighting.
I've used a document called "Keywords.doc", which
contains single word paragraphs for each of the search
terms. Note that you'll have to change file and path info
to suit your setup.
Paste this code into the document where you want to do
your highlighting. Look at the code comments, but it's
fairly basic, so I hope you can follow it without any
problems.
The routine fills an array from the keywords doc and then
uses that data in a simple find/replace.
Hope that helps,
Dennis
---------------
Sub ShowMyWords()
Dim lngCounter As Long
Dim strText As String
Dim astrSearchTerms() As String
'Open your keywords document
Documents.Open FileName:="c:\tmp\keywords.doc"
'Size an array to the number of terms
lngParaCount = ActiveDocument.Paragraphs.Count
ReDim astrSearchTerms(lngParaCount - 1)
'Fill the array with the search terms
For lngCounter = 1 To lngParaCount
strText = ActiveDocument.Paragraphs(lngCounter). _
Range.Text
astrSearchTerms(lngCounter - 1) = _
Left(strText, Len(strText) - 1)
Next
'Close your keywords document
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Highlight the search terms in the active document.
lngCounter = 0
While astrSearchTerms(lngCounter) <> ""
With ActiveDocument.Content.Find
.Wrap = wdFindAsk
.Replacement.Highlight = True
.Execute FindText:=astrSearchTerms(lngCounter), _
ReplaceWith:="", Replace:=wdReplaceAll, _
Forward:=True
End With
lngCounter = lngCounter + 1
Wend
End Sub
---------------
a word doc. if there are matches in the doc., i'd like to-----Original Message-----
hi,
good morning. i have a list of keywords to search for in
mark them (make selection?), and to highlight the matched
words wt colors.
doc., know the location of the words, and be able toin vba for word xp, could i get a list of words from a
highlight them if necessary?