Write to XFA form using VBA
Hi,
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[0].mainpage[0].header[0].Table1[0].Row4[0].SUPPLIER_CONTACT[0]"
How can I get the VBA to write to the PDF form fields?
I have tried:
fld.value = "TEXT"
jso.xfa.form("data[0].mainpage[0].header[0].Table1[0].Row4[0].SUPPLIER_CONTACT[0]").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"
Exit Function
End If
Set jso = PDDoc.GetJSObject
'jso.console.Show
jso.console.Clear
'acroApp.Show
Range("A1").Select
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
ActiveCell.Offset(1, 0).Select
Next FldNum
PDDoc.Save 1, "C:\Temp\BlankConForm2.pdf"
MsgBox "Finished"
End Function
