Link to home
Start Free TrialLog in
Avatar of Si Ball
Si BallFlag for United Kingdom of Great Britain and Northern Ireland

asked on

excel VBA to read fields from an adobe pdf form

Hello.

My friend has people sending him completed pdf forms.  He has been typing in the form contents into a spreadsheet.  I said it could probably be done with VBA... should have looked around first...

Found lots of stuff about using the Acrobat writer softwares DLL as a reference in VBA in order to write data into a form from excel, but i don;t have writer software, and i'd like to import the fields data.

i can manage vba to browse for pdf file and get filename and path.. and i read that a pdf is only a tar'd xml file...

does anyone know a quick / easy / free (delete as appropriate) method for importing the data from a pdf form into excel.

cheers

Sudo.
Avatar of Si Ball
Si Ball
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

further info:

i found this article :
https://www.experts-exchange.com/questions/26489233/PDF-Fields.html?sfQueryTermInfo=1+10+30+excel+form+pdf+vba

which calls this code:

 
Private Sub CommandButton1_Click()
    Dim AcroApp As Acrobat.CAcroApp
    Dim theForm As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim text1, text2 As String
    
    Set AcroApp = CreateObject("AcroExch.App")
    Set theForm = CreateObject("AcroExch.PDDoc")
    theForm.Open ("C:\temp\sampleForm.pdf")
    Set jso = theForm.GetJSObject
    
    ' get the information from the form fiels Text1 and Text2
    text1 = jso.getField("Text1").Value
    text2 = jso.getField("Text2").Value
    
    MsgBox "Values read from PDF: " & text1 & " " & text2
    theForm.Close
     
    AcroApp.Exit
    Set AcroApp = Nothing
    Set theForm = Nothing
     
    MsgBox "Done"
End Sub

Open in new window


but when i try and run it i get an error, presumably as i do not have acrobat as a reference..

 Set gApp = CreateObject("AcroExch.App") ' make acrobat session

Runtime Error 429
ActiveX component cannot create object
Is it not available in your > Tools > References > Acrobat ?

HTH,
Daniel
Also you need to have the Full version of Acrobat to get this code work, with only the Reader version you cant.

HTH,
Daniel
ASKER CERTIFIED SOLUTION
Avatar of Si Ball
Si Ball
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.