Hoping somebody can help with a VBA (using Excel) question. I have reasonable understanding of VBA but have never worked with PDF forms until now.
I have written VBA code to extract field names from a PDF document (Adobe XML form created in Adobe LiveCycle I beleive).
Example field name = "data.mainpage.header.Table1.Row4.SUPPLIER_CONTACT"
How can I get the VBA to write to the PDF form fields?
I have tried:
fld.value = "TEXT"
jso.xfa.form("data.mainpage.header.Table1.Row4.SUPPLIER_CONTACT").rawvalue = "TEXT"
but these do not appear to work. No error messages.
For info, here is the VBA for getting the field names:
Public Function PDFForm2()
Dim acroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim jso As Object, fld As Object, page As Object, xfaObj As Object
Dim numFields As Integer, FldNum As Integer, numFldNodes As Integer, numPages As Integer, PageNum As Integer
Dim fldName As String, FormPath As String, XML As String, XMLPath As String
Set acroApp = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
FormPath = "C:\Temp\BlankConForm.pdf"
If Not PDDoc.Open(FormPath) Then
MsgBox "Couldn't open PDDoc", vbInformation, "ERROR in GetFillablePDFNames"
Set jso = PDDoc.GetJSObject
numPages = jso.xfa.host.numPages
numFields = jso.numFields
For FldNum = 1 To 100
fldName = jso.GetNthFieldName(FldNum)
ActiveCell.Value = fldName
Set fld = jso.getfield(fldName) 'set a field object
ActiveCell.Offset(0, 1).Value = fld.Value
PDDoc.Save 1, "C:\Temp\BlankConForm2.pdf"
Thanks for your respose. The only references I am running currently in this VBA are:
- Visual Basic For Applications
- Microsoft Excel 16.0 Object Library
- OLE Automation
- Microsoft Office 16.0 Object Library
- Adobe Acrobat 10.0 Type Library
XFA scripting is more complex than regular AcroForm scripting and by necessity involves using a lot of XML objects. These do not translate well across the VBA/AcroJS boundary. It would be much easier and more productive for you to develop the code that works on the XFA model first in the Acrobat Console window, and then as a folder level function. Then call this function from VBA, passing in simple scaler arguments.
XFA development is very different than for an AcroForm. You'll find several articles here that include both AcroForm and XFA examples.
For example, this one on lists, that includes some discussion on XFA programing.