Thursday, December 19, 2013

Function to Find a specific word in a document

Set oWord = CreateObject("Word.Application")
oWord.DisplayAlerts = 0
Set oDoc = oWord.Documents.Open("path of the file")
searchString = "TEST"
For n = 1 To oDoc.Paragraphs.Count
startRange = oDoc.Paragraphs(1).Range.Start
endRange = oDoc.Paragraphs(1).Range.End
Set tRange = oDoc.Range(startRange, endRange)
tRange.Find.Text = searchString
tRange.Find.Execute
If tRange.Find.Found Then
msgbox "Word found in the document"
End If
Next
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing

No comments:

Post a Comment