Using Visual basic to search string in PDF files (acroavdoc.findtext)

Copy link to clipboard
Copied
Hello,
Using Excel 2010 and Adobe Acrobat Standard XI, I am trying to create a VBA script searching PDF files for a specified string.
According to object brovser in VBA the acroAVDoc.findtext is specified as:
Function FindText(szText As String, bCaseSensitive As Long, bWholeWordsOnly As Long, bReset As Long) As Boolean
The code below works EXCEPT that I can not manage to make the search case sensitive or for whole Words only! Anobody who can help?
Sub AcrobatFindText2()
'variables
Dim Resp 'For message box responses
Dim gPDFPath As String
Dim sText As String 'String to search for
Dim sStr As String 'Message string
Dim foundText As Long 'Holds return value from "FindText" method
Dim caseSensitive As Long
caseSensitive = 1000
Dim WholeWords As Long
WholeWords = 1000
Dim bReset As Long
bReset = 1000
'Dim ln0 As Long
'Dim ln1 As Long
'ln0 = 0
'ln1 = 1
'hard coding for a PDF to open, it can be changed when needed.
gPDFPath = "C:\*path*"'Initialize Acrobat by creating App object
Set gApp = CreateObject("AcroExch.App", "")
gApp.Hide'Set AVDoc object
Set gAvDoc = CreateObject("AcroExch.AVDoc")' open the PDF
If gAvDoc.Open(gPDFPath, "") Then
sText = "STRING TO FIND IN PDF""PROBLEM STARTS HERE"
'Function FindText(szText As String, bCaseSensitive As Long, bWholeWordsOnly As Long, bReset As Long) As Boolean
foundText = gAvDoc.FindText(sText, caseSensitive, WholeWords, bReset) 'Returns -1 if found, 0 otherwise"PROBLEM ENDS HERE"
Debug.Print foundText
Else ' if failed, show error message
Resp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)End If
If foundText = -1 Then
'compose a message
sStr = "Found: " & sText
Resp = MsgBox(sStr, vbOKOnly)
Else ' if failed, 'show error message
Resp = MsgBox("Cannot find: " & sText, vbOKOnly)
End If
'Visa dokument
gApp.Show
gAvDoc.BringToFront
End Sub

Copy link to clipboard
Copied
Although 1000 should work, have you tried setting value of your Boolean parameters to 1? Don't use VB's True since it is -1, not 1.

