Consulting

Results 1 to 9 of 9

Thread: How do I auto-populate an Acrobat form from Excel?

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    How do I auto-populate an Acrobat form from Excel?

    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?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

    [vba]
    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
    [/vba]

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Hi Stan

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

    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?
    [vba]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[/vba]
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    I think just the type lib is needed.

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

    [vba]
    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

    [/vba]

    Stan

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Thanks Stan,
    I'm excited to try this out. May not have time today but will as soon as I can.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    Stan, I am having the same challenge but not sure how to add this code. Can you ping me?
    Kindly,
    JEnnifer

  8. #8
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    1
    Location

    Library Problem

    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.

  9. #9
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    1
    Location
    How did you use VBA to make fields readonly? I need the code to make 1 specific field read only.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •