Copy link to clipboard
Copied
Hi,
I am attempting to implement AVDoc.FindText in an excel VBA script to find and highlight all instances of a search term in a document. Here is the code I have:
Dim AcroApp, AcroAVDoc
Dim gPDFPath, bReset, nCount
gPDFPath = "PATH TO FILE"
' ** Initialize Acrobat by creating App object
Set AcroApp = CreateObject("AcroExch.App")
' ** show Acrobat
Call AcroApp.Show
' ** Set AVDoc object
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
' ** open the PDF
If AcroAVDoc.Open(gPDFPath, "") Then
Call AcroAVDoc.BringToFront
bReset = True: nCount = 0
Do While AcroAVDoc.FindText("Text to Find", True, True, bReset)
bReset = False: nCount = nCount + 1
Loop
...
End Sub
But the problem is that the Do While Loop does not seem to resolve itself. Once the FindText function finds the last instance of text in the document, it then finds the next instance, on Page one. This of course causes that while loop to never terminate.
Anyone know what my issue could be, am I interpreting incorrectly how BReset should be working?
Adobe 2017 Pro (2017.011.30110)
Excel 2010
Copy link to clipboard
Copied
The documentation is silent on whether searches without bReset TRUE should wrap. You assume/wish it wouldn't, but I guess it might, so you can check if it goes backwards and terminate in that case.