Public Function fnFindInWordDocument(strFilePath, strStringToFind)
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open(strFilePath)
isFound =False
For n = 1 To oDoc.Paragraphs.Count
startRange = oDoc.Paragraphs(n).Range.Start
endRange = oDoc.Paragraphs(n).Range.End
Set tRange = oDoc.Range(startRange, endRange)
tRange.Find.Text = strStringToFind
tRange.Find.Execute
If tRange.Find.Found Then
isFound =True
Exit For
End If
Next
If isFound =True Then
fnFindInWordDocument =True
Else
fnFindInWordDocument =False
End If
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing
End Function
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open(strFilePath)
isFound =False
For n = 1 To oDoc.Paragraphs.Count
startRange = oDoc.Paragraphs(n).Range.Start
endRange = oDoc.Paragraphs(n).Range.End
Set tRange = oDoc.Range(startRange, endRange)
tRange.Find.Text = strStringToFind
tRange.Find.Execute
If tRange.Find.Found Then
isFound =True
Exit For
End If
Next
If isFound =True Then
fnFindInWordDocument =True
Else
fnFindInWordDocument =False
End If
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing
End Function
No comments:
Post a Comment