Error Searching Adobe PDF for string from excel

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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Probably a little late to answer this, but I'm having the same problem.

My solution was to add a delay to the code itself using (Below is for 400ms):

Application.Wait (Now + 0.000004)

Unfortunately this slows down the code significantly also you need to time the delay depending on the pdf loading time. I have had to increase it to 3 seconds for some larger pdfs. I'm also looking for a way to get rid of the strobing lights on my montior. When I hide the function and increase the delay it seems to work, but it seems more efficient leaving the strobe working with a smaller delay.
 
Upvote 0
Probably a little late to answer this, but I'm having the same problem.

My solution was to add a delay to the code itself using (Below is for 400ms):

Application.Wait (Now + 0.000004)

Unfortunately this slows down the code significantly also you need to time the delay depending on the pdf loading time. I have had to increase it to 3 seconds for some larger pdfs. I'm also looking for a way to get rid of the strobing lights on my montior. When I hide the function and increase the delay it seems to work, but it seems more efficient leaving the strobe working with a smaller delay.

I still have not found a solution either. I am assuming its the main issue of excel being single threaded and not being able to do things like this in the background.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top