'----------------------------------------
'- Name: peet
'- Web:
'- Company: PvP
'----------------------------------------
'- Notes:
'- Sample to show how to search a word-
' document using automation
'
'----------------------------------------
Private objWord As Word.Application
Private wd As Word.Document
Private Sub Command1_Click()
Dim myRange As Range
Dim sSearchfor As String
sSearchfor = InputBox("What do u want to search for?")
If sSearchfor = "" Then Exit Sub
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
Else
Set objWord = GetObject(, "Word.Application")
End If
DoEvents
Set wd = objWord.Documents.Open("c:\Test.doc")
Set myRange = wd.Content
myRange.Find.Execute FindText:=sSearchfor, Forward:=True
If myRange.Find.Found Then
MsgBox "The document contains :'" & sSearchfor & "'", vbInformation
Else
MsgBox "The document do NOT contain'" & sSearchfor & "'", vbInformation
End If
If Not (wd Is Nothing) Then Set wd = Nothing
If Not (objWord Is Nothing) Then objWord.Application.Quit
If Not (objWord Is Nothing) Then Set objWord = Nothing
End Sub