A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Word 2007 Search for multiple words in 1 document



 
 
Thread Tools Display Modes
  #1  
Old August 5th, 2009, 10:57 PM posted to microsoft.public.word.docmanagement
tj7
external usenet poster
 
Posts: 2
Default Word 2007 Search for multiple words in 1 document

Is there anyway to search for multiple words in Word even if only 1 of them
is present?

i.e. search for Dog or cat or pig or horse.
  #2  
Old August 6th, 2009, 05:51 AM posted to microsoft.public.word.docmanagement
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Word 2007 Search for multiple words in 1 document

You can do so in an open document with a macro. What would you want to do
with the words having found them?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



tj7 wrote:
Is there anyway to search for multiple words in Word even if only 1
of them is present?

i.e. search for Dog or cat or pig or horse.



  #3  
Old August 7th, 2009, 06:11 PM posted to microsoft.public.word.docmanagement
tj7
external usenet poster
 
Posts: 2
Default Word 2007 Search for multiple words in 1 document

I would just want them highlighted in some manner. Basically searching for a
few needles in a large haystack and they may or may not be there.
Thanks
TJ

"Graham Mayor" wrote:

You can do so in an open document with a macro. What would you want to do
with the words having found them?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



tj7 wrote:
Is there anyway to search for multiple words in Word even if only 1
of them is present?

i.e. search for Dog or cat or pig or horse.




  #4  
Old August 8th, 2009, 06:29 AM posted to microsoft.public.word.docmanagement
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Word 2007 Search for multiple words in 1 document

If by 'highlighting' you mean 'selecting' then it is only possible to do so
one at a time.

Sub FindWords()
Dim vFindText
Dim r As Range
Dim i As Long
vFindText = Array("dog", "cat", "pig", "horse")
For i = 0 To UBound(vFindText)
Set r = ActiveDocument.Range
With r.Find
.Text = vFindText(i)
Do While .Execute(Forward:=True) = True
r.Select
MsgBox r
Loop
End With
Next
End Sub

If however you mean highlighting as in adding a coloured background, then
that is easy enough to achieve using a macro

Sub HiLightList()
Dim vFindText
Dim r As Range
Dim i As Long
vFindText = Array("dog", "cat", "pig", "horse")
For i = 0 To UBound(vFindText)
Set r = ActiveDocument.Range
With r.Find
.Text = vFindText(i)
Do While .Execute(Forward:=True) = True
r.HighlightColorIndex = wdYellow
Loop
End With
Next
End Sub

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




tj7 wrote:
I would just want them highlighted in some manner. Basically
searching for a few needles in a large haystack and they may or may
not be there.
Thanks
TJ

"Graham Mayor" wrote:

You can do so in an open document with a macro. What would you want
to do with the words having found them?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



tj7 wrote:
Is there anyway to search for multiple words in Word even if only 1
of them is present?

i.e. search for Dog or cat or pig or horse.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.