bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I have created a function that can search through various document types. My issue is searching through pdfs I get Microsoft excel is waiting for another application to complete an ole action error message and it hangs until I hit the OK button. Is there a way to avoid this message and keep the code running until its done and not need the user to babysit in case that comes up? Also if I uncheck the bringtofront method it doesnt seem to do that anymore but I really did not want the user to see the pdfs cycling. Also, if I could hide this adobe object completely from the user that would be great because if i do not bring to front i can still see it in the task bar.
Code:
Function SearchDocument(ByRef AppObject As Object, FilePath_Export As String, WordsToFind() As String) As String
Dim lCounter As Long
Dim WordsFound As String
On Error GoTo ErrorHandler
Select Case LCase(Right(FilePath_Export, 4))
Case Is = ".pdf" 'Check if pdf document
If AppObject Is Nothing Then
'create pdf object
Set PDFObj = CreateObject("AcroExch.App")
End If
Dim AVDocObj As Object
Set AVDocObj = CreateObject("AcroExch.AVDoc")
If AVDocObj.Open(FilePath_Export, "") = True Then
'AVDocObj.BringToFront
For lCounter = 0 To UBound(WordsToFind)
If AVDocObj.findtext(WordsToFind(lCounter), False, False, False) = True Then
If WordsFound = "" Then
WordsFound = WordsToFind(lCounter)
Else
WordsFound = WordsFound & ", " & WordsToFind(lCounter)
End If
End If
Next
End If
AVDocObj.Close True
SearchDocument = WordsFound
End Select
Exit Function
ErrorHandler:
Debug.Print Err.Description
SearchDocument = "Error"
End Function