Fill in a PDF form from VBA (MS-Access)

旧时模样 提交于 2019-11-30 14:16:33

Finally managed to get something working after merging some lines of code. Here it is. It works with the Adobe Acrobat 9.0 Type Library set as reference in my VBA project.

Dim FileNm, gApp, avDoc, pdDoc, jso

FileNm = "c:\form.pdf" 'File location
Set gApp = CreateObject("AcroExch.app")

Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(FileNm, "") Then
    Set pdDoc = avDoc.GetPDDoc()
    Set jso = pdDoc.GetJSObject

    jso.getField("topmostSubform[0].Page1[0].fieldName[0]").value = "myValue"
    pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document
    pdDoc.Close
End If

'Close the PDF; the True parameter prevents the Save As dialog from showing
avDoc.Close (True) 

'Some cleaning
Set gApp = Nothing
Set avDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing

Note that topmostSubform[0].Page1[0] is the default name that Adobe LiveCycle Designer gives to your main PDF document, while fieldName[0] is the name of your field. If you have multiple fields with the same name, Adobe LiveCycle Designer automatically adds index numbers so you can easily loop through your fields.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!