C
c.piyush
The number of words in the word document can be many.
I have written the code for opening a document and then finding a
particular word but i don't know how to navigate the whole word
document for that particular word and highlight it.
This is what i've written till now:
Private Sub Command1_Click()
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim strFileName As String
Dim strFind As String
strFind = "Piyush"
strFileName = "C:\Test1.doc"
Set appWord = New Word.Application
Set wrdDoc = appWord.Documents.Open(strFileName)
appWord.Selection.Find.Text = strFind
If appWord.Selection.Find.Execute = True Then
MsgBox ("Text found.")
Else
MsgBox ("The text could not be located.")
End If
Set wrdDoc = Nothing
Set appWord = Nothing
End Sub
Kindly look into this and help complete me code.
Thanks.
I have written the code for opening a document and then finding a
particular word but i don't know how to navigate the whole word
document for that particular word and highlight it.
This is what i've written till now:
Private Sub Command1_Click()
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim strFileName As String
Dim strFind As String
strFind = "Piyush"
strFileName = "C:\Test1.doc"
Set appWord = New Word.Application
Set wrdDoc = appWord.Documents.Open(strFileName)
appWord.Selection.Find.Text = strFind
If appWord.Selection.Find.Execute = True Then
MsgBox ("Text found.")
Else
MsgBox ("The text could not be located.")
End If
Set wrdDoc = Nothing
Set appWord = Nothing
End Sub
Kindly look into this and help complete me code.
Thanks.