# Extract specify values from PDF files using VBA



## noppph

*Hello Lovely people,*

I'm trying to get specify text from a group of PDF file,
Now I can open then use some keyword to search and return if the specify text is exist using the code below.

*I want to.*
1. Return the text next to specify text i.e. find "Name" from "Name:Mary Jane", I want to get Mary Jane as return.(Need to have)
2. Find the data for specify occurrence, i.e. the specify string might exist more than one, so i want to specify which occurrence to be processed.(Need to have)
3. How to specify range of page to be searched, do not look through the whole document.(nice too have)
4. Loop through all PDF files in the specify directory(nice to have)

My sample file: https://drive.google.com/folderview?id=0BzzGCWOB7fHJalpHalJwMUF3SUk&usp=sharing
Reference of code: http://www.mrexcel.com/forum/excel-...ing-excel-2010-visual-basic-applications.html



		Code:
__


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 Integer 'Holds return value from "FindText" method


'hard coding for a PDF to open, it can be changed when needed.
gPDFPath = "D:\Dropbox\Misc\ReadPDF_VBA\1_Mark.pdf"


'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 = "Tester"
'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), 'ResetSearchToBeginOfDocument (1 or 0)
foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise


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


gApp.Show
gAvDoc.BringToFront


End Sub


'1. Return the text next to specify text i.e. find "Name" from "Name:Mary Jane", I will get Mary Jane
'2. Find the data for specify occurence, i.e. there might be some string "Name" which are
'3. How to specify range of page to be searched, do not look through the whole document, just my specify pages


----------



## noppph

I'm tried but can't get the text next to my search text. sad


----------



## noppph

Anyone have facing this kind of task ?


----------



## noppph

I've read the Acrobat library, but no luck don't know how to fix this.
Can someone give any suggestion ?

Thanks


----------



## Tayl4n

Hey I'm also waiting for this supported this topic


----------

