PDA

View Full Version : How do I auto-populate an Acrobat form from Excel?



TrippyTom
03-05-2009, 06:15 PM
I know this is more of an Acrobat question, but figured I'd try to ask it here since I'm more familiar with this forum. (I have not cross posted this in the Adobe forums because, frankly, those forums are a mess and it takes forever to get any kind of reply).

Anyway, here's my situation:
Excel 2003
Adobe Acrobat Professional version 7
(comes with Adobe Designer 7 as well, in case I need to utilize that somehow in the solution)

My boss asked me if there was a way to "auto populate a Fillable PDF form, from an excel sheet". Does anyone know the simplest way to do this with the current versions of the software I posted above? Is it even possible, or will we need to upgrade the software?

stanl
03-11-2009, 03:47 AM
It is possible is you wish to get started with the Acrobat API. Basically you would write Excel modules to create the necessary Acrobat Objects, then populate the forms, then perhaps [as I did with an Excel invoice that was used to populate a pdf form] - mark the fields as readonly. Below is sample code that gets one to the form field objects. Stan


Public Sub Main()
Dim AcroApp As Acrobat.CAcroApp
Dim AvDoc As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sFieldName As String
Dim Field As AFORMAUTLib.Field
Dim Fields As AFORMAUTLib.Fields
Dim AcroForm As AFORMAUTLib.AFormApp

Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")

If AvDoc.Open("C:\test\testform.pdf", "") Then
AcroApp.Show
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count
MsgBox fcount
For Each Field In Fields
sFieldName = Field.Name
MsgBox sFieldName
Next Field
Else
MsgBox "failure"
End If
AcroApp.Exit
Set AcroApp = Nothing
Set AvDoc = Nothing
Set Field = Nothing
Set Fields = Nothing
Set AcroForm = Nothing

TrippyTom
03-11-2009, 08:47 PM
Hi Stan :)

Thanks for your reply. I was secretly hoping you would just tell me it couldn't be done. :rotlaugh:

But now that you've opened my eyes a little, I'm curious to find out more. Am I right in presuming I have to add a reference to the Adobe library? If so, which one? Is it one of the last 3 perhaps?
Acrobat Access 3.0 Type Library
Acrobat Distiller
Acrobat WebCapture 1.0 Type Library
Acrobat WebCapture IE Toolbar/Favorites 1.0 Type Library
AcroIEHelper 1.0 Type Library
Adobe Acrobat 5.0 Type Library
Adobe Acrobat 7.0 Browser Control Type Library 1.0
Adobe Acrobat 7.0 Type Library

stanl
03-12-2009, 02:35 AM
I think just the type lib is needed.

stanl
03-12-2009, 04:44 AM
Oh, I should have mentioned that since the code snippet uses late-binding you may not even need to add a reference... just means you have to hard-code some stuff. You should be able to easily test inserting data with that code... something like


For Each Field In Fields
sFieldName = Field.Name
If sFieldName = "Field1" Then Field.Value = [Excel cell Value]...
If sFieldName = "Field2" Then Field.Value = [Excel cell Value]...
etc...
Next Field



Stan

TrippyTom
03-12-2009, 04:56 AM
Thanks Stan,
I'm excited to try this out. May not have time today but will as soon as I can.

stralim
10-06-2010, 07:27 AM
Stan, I am having the same challenge but not sure how to add this code. Can you ping me?
Kindly,
JEnnifer

RobRoy
09-14-2012, 12:37 AM
Hi,

I am trying to use the mentioned code for my pdf-form also. Everything looks fine and correct, but I am getting a runtime error when I am creating the neccessary objects.
At ...
Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")
... it says "Runtime Error 429: ActiveX component can't create object."

Why??
I am using Office 10, Adobe Reader X and PDFCreator.
References are set to Adobe Acrobat 10 Type Library, PDFCreator and other adobe libs.

Anyone an idea, why i get this error ??

MAAAAAAAAAAAANY THX for help. :bug:

Tina2020
06-02-2020, 01:36 PM
How did you use VBA to make fields readonly? I need the code to make 1 specific field read only.