Extract specify values from PDF files using VBA

noppph

New Member
Joined
Feb 22, 2016
Messages
47
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
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I've read the Acrobat library, but no luck don't know how to fix this.
Can someone give any suggestion ?

Thanks
 
Upvote 0
Hey I'm also waiting for this supported this topic
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,005
Members
449,092
Latest member
masterms

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