VB script search for specific words - Word 2003 Documents

Hello

I'm trying to make a VBscript that searches for specific words... for example

color
center
fiber

Can anyone provide a simple function that can be given an array of words and return true if any of them are found?

The script would be run from command line in Windows, rather than as a VBA script within Word itself.

The version of Word we are using is Word 2003.

Thanks

BH
LVL 1
butterhookAsked:
Who is Participating?
 
Muhammad KhanConnect With a Mentor Manager, ITCommented:
Dim Word
Set Word = CreateObject ("word.application")
set document = word.documents.open( "c:\workshop\worddoc.doc") 'Replace the document name with y our own
'msgbox document.name
searchWhat = inputbox ("search what? comma seperate multiple search terms")
searchWhatArray=split(searchWhat,",")
searchCount=0
found=""
foundWhat=""

With document
set tRange=.content
'msgbox .content
for x = lbound(searchWhatArray) to ubound(searchWhatArray)
'msgbox "Searching " & searchWhatArray(x)
set tRange=.content
      tRange.Find.Text = trim(searchWhatArray(x))
      tRange.Find.Execute
'      msgbox tRange.find.Found
      If tRange.Find.Found Then
            found=true
            foundwhat=foundWhat & vbcrlf & searchWhatArray(x)
            
      End If
next
if found then
 msgbox "Found " & foundWhat
end if
End With

word.quit

save it as vbs...
0
 
butterhookAuthor Commented:
Thanks. I'll try this out a little later and get back to you ASAP.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.