Reading And Modifying PDF Form Fields with VBA

I’ve written about VBA and Acrobat JavaScript before, and I’ve also mentioned that you can combine VBA and JavaScript to access PDF form fields, but I still owe a sample for that. I had to answer another question today about how to exactly do that, so I whipped up a quick sample program that demonstrates the use of the JavaScript Object (JSO) to read and write AcroForm fields.

We start the same way as in my old VBA sample to create a VBA program that references the Acrobat TLB and to add a button to a document. When we now use the following script as the button handler, we can work with form fields:

Private Sub CommandButton1_Click()
    Dim AcroApp As Acrobat.CAcroApp
    Dim theForm As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim text1, text2 As String

    Set AcroApp = CreateObject("AcroExch.App")
    Set theForm = CreateObject("AcroExch.PDDoc")
    theForm.Open ("C:\temp\sampleForm.pdf")
    Set jso = theForm.GetJSObject

    ' get the information from the form fields Text1 and Text2
    text1 = jso.getField("Text1").Value
    text2 = jso.getField("Text2").Value

    MsgBox "Values read from PDF: " & text1 & " " & text2

    ' set a text field
    Dim field2 As Object
    Set field2 = jso.getField("Text2")

    field2.Value = 13   ' assign the number 13 to the fields value

    ' get the information from the form fields Text1 and Text2
    text1 = jso.getField("Text1").Value
    text2 = jso.getField("Text2").Value

    MsgBox "Values read from PDF: " & text1 & " " & text2

    theForm.Close

    AcroApp.Exit
    Set AcroApp = Nothing
    Set theForm = Nothing

    MsgBox "Done"
End Sub

This program requires a PDF file with text fields called “Text1” and “Text2” to be stored as C:\temp\sampleForm.pdf. With the explanation in the previous two blog posts, it should not be hard to understand what’s going on here. The only new command introduced is the getField() function, which returns a form field. The form field object has a property “value” which contains the actual value that’s assigned to the field. Give it a try and let me know how it works for you. The updated form field is not saved (because the document does not get saved) – I’ll leave that up to the reader to figure out.

Also, this program will not work with XFA forms (the ones you create in Designer). For those, you need to use the XFA DOM to access the form data. For anybody interested in XFA forms, the LifeCycle Designer ES Scripting Reference is a must read.

This entry was posted in Acrobat, JavaScript, PDF, Programming and tagged , , , , . Bookmark the permalink.

74 Responses to Reading And Modifying PDF Form Fields with VBA

  1. Wayne says:

    Hi there,

    This is exactly what I am looking for. Thanks so much.
    However, my assignments are a bit different. I am wondering if you can give me a hand.

    The data source:
    1. An excel spreadsheet storing the raw data
    2. A PDF file with an interactive form used to store the data input by the user according to the above excel spreadsheet

    My assignments:
    1. input the raw data from excel spreadsheet to the PDF interactive form
    2. double check if the data input in the PDF interactive form is correct.

    I am not allowed to convert the Excel spreadsheet to the PDF file directly as the PDF file is the template with precise paragraphing and wording embedded. It is a heavy job when there are over hundreds of number. I am thinking if the excel VBA can do both assignments automatically or at least double check my input.

    Thanks.
    Wayne

  2. Wayne says:

    Hi khk,
    I have adobe 9.1 professional and excel 2007, adobe TLB added.

    F8 stepinto F8 found “Runtime error ‘424’, object required”
    debug at this code ” text1 = jso.getField(“Text1″).Value”

    don’t know why?

    Thanks
    Wayne

  3. Wayne says:

    oh, “t” not “T”, i got it.
    btw, we can use the call function to save the updates.
    call theForm.Save(PDSaveFull,”C:\temp\sampleForm.pdf).

  4. Matt Conklin says:

    How do you test to make sure that the field exists in the form. I don’t want an error message when the user selects the wrong .PDF form to import into the spreadsheet.

    “On Error goto 0” does not trap the error.

    Is there a method such as FieldExists(“text1”) that I could use to trap that error before using the getField() method.

  5. admin says:

    I don’t know about VB (remember, I said that I am not working in VB). You can do test if a field exists in JavaScript by testing the value returned by getField():

    var f = this.getField("test");
    if (f == null)
    {
    app.alert("f does not exist");
    }

  6. Daryl says:

    In Excel 2010 VBA, I am trying to create a series of PDF forms each individually filled out but then combine them into a single PDF. I’ve tried a number of things but I keep getting stuck on the single PDF creation. Here’s what I currently have. The individual forms get created and saved with the correct data. However when I try to build the single PDF, it has the correct number of forms but the data is all filled in identically. This is the same problem that happens if you try to combine like forms into a single PDF in Adobe.

    In Adobe Acrobat you can avoid that problem by “flattening” the individual PDF files so that the form field names are removed and the data in the form cannot be edited. After that is completed, you can combine the individual PDF files and the field data is not overwritten. Is there a way to mimic that in Excel VBA? I actually do not even need to save the individual forms — only the single “combined” PDF. I only did that in this code because I thought it might help (it didn’t).

    I’d certainly appreciate any help or insight on this.

    Sub Process_Manual_Input()

    bProcessSuccessful = False

    sDefName = “ABC Fund – Forms 62 (xx.xx.xx).pdf”
    vFileName = Application.GetSaveAsFilename(sDefName, “PDF Files (*.pdf), *.pdf”)

    If vFileName = False Then
    End
    Else
    sPath = Left(vFileName, Len(vFileName) – 4)
    sFile = Right(vFileName, Len(vFileName) – InStrRev(vFileName, “\”))
    MkDir sPath
    End If

    Set oAcroApp = CreateObject(“AcroExch.App”)
    Set oEmbeddedPDF = CreateObject(“AcroExch.PDDoc”)
    Set oManipPDF = CreateObject(“AcroExch.PDDoc”)
    Set oTempDoc = CreateObject(“AcroExch.PDDoc”)
    Set oFullPDF = CreateObject(“AcroExch.PDDoc”)

    ‘ Open Form 62 template

    szO = oEmbeddedPDF.Open(wsRequest.Range(“File62”).Value)
    ‘ Set oManipAV = oEmbeddedPDF.OpenAVDoc(“Form 62”)

    With wsManual
    lRow = .Range(“HeadingRow”).Row + 1
    lEndRow = .UsedRange.Rows.Count
    lNumPages = 0
    lNumFullPages = 0

    Do Until lRow > lEndRow

    szO = oManipPDF.Create
    szO = oManipPDF.InsertPages(-1, oEmbeddedPDF, 0, 3, 1)

    Set oManipAV = oManipPDF.OpenAVDoc(“Form 62”)

    Set oAcroForm = CreateObject(“AFormAut.App”)
    Set oAcroFields = oAcroForm.Fields

    oAcroFields.Item(“sFundName62”).Value = sFName
    oAcroFields.Item(“sStreet62”).Value = sStreet
    oAcroFields.Item(“sCityStateZip62”).Value = sCitStZip
    oAcroFields.Item(“sEIN62”).Value = sEIN

    For Each oAcroField In oAcroFields
    oAcroField.IsReadOnly = True
    Next

    sSecName = Trim(Replace(.Cells(lRow, mSecName), “/”, “-“))

    s62FileName = sPath & “\(” & sSecName & _
    ” – ” & Trim(CStr(.Cells(lRow, mSecID))) & “) ” & sFile

    szO = oManipPDF.Save(1, s62FileName)

    oManipPDF.Close

    oTempDoc.Open (s62FileName)

    lNumPages = oTempDoc.GetNumPages()

    ‘ szO = oManipPDF.Save(1, sPath & “\(” & sSecName & _
    ‘ ” – ” & Trim(CStr(.Cells(lRow, mSecID))) & “) ” & sFile)

    If lNumFullPages > 0 Then
    szF = oFullPDF.InsertPages(lNumFullPages – 1, oTempDoc, 0, 3, 1)
    lNumFullPages = oFullPDF.GetNumPages()
    ‘ lNumFullPages = lNumFullPages + lNumPages
    ElseIf lNumFullPages = 0 Then
    Set oFullAV = oFullPDF.OpenAVDoc(“Full 62”)
    szF = oFullPDF.Create
    szF = oFullPDF.InsertPages(-1, oTempDoc, 0, 3, 1)
    lNumFullPages = oFullPDF.GetNumPages()
    ‘ lNumFullPages = lNumPages
    Else
    MsgBox “Error Writing to Full PDF”
    Exit Sub
    End If

    oTempDoc.Close

    lRow = lRow + 1
    Loop

    If oFullPDF.Save(1, sPath & “\” & sFName & ” 62s.pdf”) = False Then
    MsgBox “Save Failed”
    End If

    oFullPDF.Close
    bProcessSuccessful = True

    End With

    Exit Sub

    ER_Handler:
    MsgBox Error$
    On Error Resume Next
    ‘Resume
    oAcroApp.CloseAllDocs
    oAcroApp.Exit
    Set oAcroApp = Nothing
    Set oManipPDF = Nothing
    Set oEmbeddedPDF = Nothing
    Set oManipAV = Nothing
    wbManual.Close False
    Set wsManual = Nothing

    Application.ScreenUpdating = True

    End Sub

  7. Karl Heinz Kremer says:

    Yes, you can flatten with VBA – but you need to use the JSObject interface and then call jso.flattenPages(). Take a look at this post, which explains how the JSO gets used: http://khkonsulting.com/2009/03/acrobat-javascript-and-vb-walk-into-a-bar/

    Here is information about the flattenPages method: http://livedocs.adobe.com/acrobat_sdk/11/Acrobat11_HTMLHelp/JS_API_AcroJS.89.472.html

  8. Charles says:

    Does anybody know how to read the document restricions summary by excel vba?

    I get an error when certain document restictions are set, but I cannot figure out if they are set.

    For example, I am looking for how to read:
    “Printing” is “allowed”
    “Changing the document” is “allowed”
    and Document assembly, Content copying, content copying for accessibility, page extraction, commenting, filling the form fields, signing, creation of template pages

  9. jaime says:

    Using an excel macro, I need code to find text strings in the pdf and hilite the text or add comments/annotations to multiple strings that are listed in column A.

  10. Karl Heinz Kremer says:

    This is impossible to do in VBA, you would need to use the JSObject to do most of the work in JavaScript, and even there, it would be a very complex task.

  11. Pingback: Read Pdf fields

  12. Kelsey says:

    Hi, I am using VBA to add a combobox to a pdf document. Do you know of a way to add the properties to the combobox? I would appreciate any help!

    Dim App As CAcroApp
    Dim PDDoc As CAcroPDDoc
    Dim jso As Object
    Dim i As Long
    Dim FileName As String
    Dim field As Object
    Dim rect(3) As Integer

    Set field = jso.addField(“Performance”, “combobox”, 0, rect)

    Set jso = PDDoc.GetJSObject

    rect(0) = 182 ‘ x lower left
    rect(1) = 762 ‘ y lower left
    rect(2) = 297 ‘ x upper right
    rect(3) = 742 ‘ y upper right

    i = PDDoc.Save(PDSaveIncremental, FileName)
    End If
    PDDoc.Close

  13. Karl Heinz Kremer says:

    Kelsey,

    there are a number of problems with your code. You are using rect and so before they are defined. There is an “End If” without an “if”, and there are things missing at the beginning to open a PDDoc.

    Try something like this:

    Dim App As Acrobat.CAcroApp
    Dim PDDoc As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim i As Long
    Dim FileName As String
    Dim field As Object
    Dim rect(3) As Integer
    Dim items(3) As String

    App = CreateObject("AcroExch.App")
    PDDoc = CreateObject("AcroExch.PDDoc")
    PDDoc.Open("C:\temp\test.pdf")

    jso = PDDoc.GetJSObject

    rect(0) = 182 ' x lower left
    rect(1) = 762 ' y lower left
    rect(2) = 297 ' x upper right
    rect(3) = 742 ' y upper right

    field = jso.addField("Performance", "combobox", 0, rect)

    field.strokeColor = jso.color.blue
    field.fillCOlor = jso.color.yellow

    items(0) = "One"
    items(1) = "Two"
    items(2) = "Three"
    field.setItems(items)

    i = PDDoc.Save(1, "C:\temp\test-out.pdf")
    PDDoc.Close()

  14. Kelsey says:

    Thank you for your help!

  15. todd says:

    We have been following your posts with some success – so many thanks. We did encounter one issue scripting acrobat from ms access/vba. Essentially we are unable to set a zip code without the (something) stripping the leading zero:

    objJSO.getfield(“Zip Code”).Value = “02110”

    In our use case the form is already pre-filled and we are just updating the zip. If we try something along the lines of:

    objJSO.getfield(“Zip Code”).Value = “David”

    we get a type error. So we are assuming that the Field object returned by getfield is typed somehow… We are looking for a solution (to maintain the leading zero), whether we need to change types or a new approach. Any help / information / ideas is greatly appreciated.

    Thank you

  16. haloween says:

    Hi
    Here’s one a little far off. Is there a way to add a value to Sharepoint Document Library in specific column beside just added PDF document? I can add PDF docs to Sharepoint but just cant find a way to add some metadata to it. I was trying with PDF document properties, but didnt get very far.
    thanks for any hints…

  17. Karl Heinz Kremer says:

    Sorry, don’t know anything about Sharepoint.

  18. agustin cereceres says:

    Hi, I am new to PDF fillable form universe so I’m a little lost. I have an Excel spreadsheet where I have simple data and I would like to create this PDF form where in the first column the user types an item code and the other fields get automatically filled in, you can easily do this in Excel with a Vlookup. How can I translate that into PDF? Also this form is going to be mobile, users will have the form in their cellphones or tablets, so I assume the database has to be there in the background or hidden. Your help will be much appreciated. Thank you.

  19. Karl Heinz Kremer says:

    Augustin, you would have to implement this in JavaScript. I would use an array with the first selected item as the index. JavaScript allow you to use not just numeric values as indices, but other “things” as well (e.g. strings). This way, you can lookup the selection of values that you need to assign to your other fields.

    When you are planning on using such a form on a mobile device, you will have to select the mobile viewer that you require first and then code for that particular viewer. Mobile PDF viewers have a lot less functionality than the desktop versions. Make sure you select one that actually supports JavaScript, and then stick to the supported methods.

  20. Hayden says:

    Hi, I am trying to get data from a PDF file into Excel using VBA. Have tried a number of different types of code and methods, running into problems.

    Planning to use this in combination with Outlook so that when a PDF invoice is received, the attachment will automatically be downloaded to a folder then the key data from the PDF will be saved on a new row in an Excel spreadsheet.

    It can be done manually, saving the PDF to Excel, then copying and pasting in various elements, so it should be able to be done using VBA. However I am struggling.

    Currently getting “Error 1001: NotAllowedError: Security settings prevent access to this property or method” from this line of code:
    jsObj.SaveAs NewFileName, “com.adobe.acrobat.spreadsheet”

    Have tried also saving as text, which would still be OK.

    Can anyone help me please?

    Thanks in advance

  21. Karl Heinz Kremer says:

    Hayden, without knowing more about your setup, it’s impossible to say what’s going on. Can you save your PDF file as an Excel file manually in Acrobat via File>Save As Other>Spreadsheet>… ? Keep in mind that this works only with Adobe Acrobat, not the free Reader. You may also want to check the security settings of your PDF file. If the file does not allow content extraction, this will not work.

  22. Branddan says:

    Hi,
    Is it possible to fill a fillable pdf form without Acrobat? I have only the Adobe Reader installed and the code above doesn’t work (obviously..)
    Thanks!

  23. Branddan says:

    Nevermind, I have found this:
    http://www.accessmvp.com/thedbguy/demos/fillablepdf.html
    and it works just fine:)

  24. Ken says:

    Do you have any tutorials on accessing the XFA DOM to get form data similar to this application? I’ve been try for a while missing objects.

  25. Karl Heinz Kremer says:

    No, I don’t have anything about the XFA DOM. You should however – with the XFA documentation – be able to figure out how to access information in the xfa object.

  26. Michelle M. says:

    Thank you so very much for all of your samples. They’ve been a lifesaver! I am using Excel VBA to populate fields on a form in Adobe Pro XI. It works wonderfully. In some instances, however, I need to hide a checkbox (Check_box20) on the form. I can’t quite figure out how to use VBA to make this happen. Any ideas?

  27. Igor N says:

    This is an excellent post! Thank you so much for all your wisdom!

    One question I have. I have a pdf with a bunch of text fields. How do I get the names of all text fields in a pdf?

  28. Karl Heinz Kremer says:

    Igor, you can use a loop like this:

    for (var i=0; i
    							
  29. wayne says:

    Hi Karl,

    I used your code to populate the PDF file successfully. The PDF file may not be created by Designer howeever. I recently had a PDF file created by designer (I guess because the ‘adds and edits the field’ option under form is gone and ‘edit in designer’ shows up when I open this file). The original macro then does not work. It says object required when running to the row jso.getField. For sure, the macro does work well when I open another PDF file which has the ‘adds and edits the field’ from form drop down list menu.

    Do you know why?
    Thanks a lot in advance.
    Wayne

  30. Karl Heinz Kremer says:

    Wayne, PDF forms created with LiveCycle Designer (or XFA forms) are not AcroForms. What I described here only works with AcroForms. You can potentially also fill in XFA forms, but for that you need to use a very different approach. You will have to manipulate the xfa data structure directly. Look at this discussion for some background: https://forums.adobe.com/thread/1690501

  31. wayne says:

    Hi Karl,

    Thanks a lot. Let me read through the contents in the link.

    Wayne

  32. EconStudent says:

    Dear Karl,

    I’ve thinking about a way to extract info from pdf for some time and now I’m trying to use the above code.
    After adding the Acrobat and Adobe references in VBA I get an error on line
    Set AcroApp = CreateObject(“AcroExch.App”)

    ActiveX component can’t create object.

    Could you please point to me how to overcome this issue ?

    Many many thanks.

  33. dhiresh says:

    i have no of pdf files, in pdf file there is field name as ‘Name’, I want list of pdf file and value of name field in front of that pdf file.
    is it possible..
    like

    a.pdf xxxxx
    b.pdf xxxxx

  34. Karl Heinz Kremer says:

    Dhiresh, You can certainly do that using VBA: Just loop through your list of files, and open one after the other in Acrobat and then extract the field value. I would then store the name of the file and the value in a list in VBA. Once you are done processing all your PDF files, just process the list that you’ve created and output the contents in the format you need. This is mostly straight VBA programming. If you are familiar with VBA, you should be able to write the loop and the list processing part without any problems, the Acrobat specific part you should be able to almost copy and paste from the code above.

  35. Pingback: Not seeing PDF fields from Excel VBA | news-rss feed form stackoverflow

  36. Greg Wolff says:

    This is good information. However, what if we do not know the actual name of the form fields. I have a secured PDF that I need to read data from, so I cannot directly access the form field names.

    Thanks!

  37. Karl Heinz Kremer says:

    Greg, you can iterate over all fields and get their names. Look at the Doc.getNthFieldName() function and the Doc.numFields property to do that.

  38. Sean says:

    Hi Karl,

    I would like to export a spreadsheet form in excel into an FILLABLE PDF form. When I use excel’s ‘Save As pdf’ the pdf file that is created is not fillable.
    Could this be done using VB?

  39. Karl Heinz Kremer says:

    Sean, in general, when you export from Excel (or Word) to PDF, all interactive fields that you had in your original document are lost. Neither Excel’s own “save as PDF”, or Adobe Acrobat’s PDFMaker will retain any interactive fields. To get these elements into a PDF file, you have two options: Create your own PDF export routine that does have the ability to recognize and export these interactive fields, or let Acrobat or Excel create the PDF file for you, and you then – in a second step – add these interactive fields to the newly created PDF file. Neither method is simple, and the fact that it’s not already available may tell you a bit how complex the issue actually is.

    The way this is usually done is by exporting a static PDF file, and then using Adobe Acrobat to manually add the interactive fields in a second step.

  40. Sean says:

    Thanks Karl. I am creating invoices in excel using comlpex formulas and would like to export these as PDF files for my staff containing interactive fields. So manually using Acrobat to add interactive fields is not feasible.

    Do you know of any discussions or open source where Visual Basic is used to create a PDF export routine with interactive fields?

  41. Karl Heinz Kremer says:

    Sean, no, I am not aware of any existing product that would do that. You may want to look into OpenOffice.org, as far as I know, it can export PDF with interactive elements. It’s a different application, which can read Excel documents, but how accurately they get reproduced is something you will have to test.

  42. Thinesh says:

    Hi,

    Need a favour…

    How to extract the comments & highlighted text in PDF trough excel VBA code.

    Thanks in advance,
    Thinesh.

  43. Karl Heinz Kremer says:

    Tinesh, take a look at the Acrobat API documentation. What you need is the JSObject from the IAC API to access all annotations. It’s a bit of work, and unfortunately, too much for what I can do in a comment on my blog. If you need professional help with this, feel free to get in touch with me via email. My email address is on my “About” page (http://khkonsulting.com/about).

  44. Nerg says:

    Hello
    Could you please help. I want to put dynamic stamp for several pdf files from excel vba. Dynamic stamp should put a date specified in excel file. I prepared the stamp, wrote macro, but it puts “Draft” stamp always. AP property doesn’t work. Also I dont know how to put specific date into dynamic stamp.

    Thank you

  45. Nerg says:

    I ‘ve found how to add specific date to dynamic stamp from vba. But still can’t fix problem with props.AP. It doesn’t work. It puts “Draft” stamp always.

  46. Karl Heinz Kremer says:

    Nerg, how are you trying to place the stamp? What code are you using?

  47. Oliver says:

    Hello,

    very interesting and very useful information here. Does anybody know, if it is possible to read the coordinates of the form fields?

    Thanks in advance,
    Oliver

  48. Karl Heinz Kremer says:
  49. Mohammad Hasanain says:

    Thank you very Much!, it help me a lot , i develop this also so i can select the Path for the PDF file and it work great with Excel VBA to Update Acro Form Fields with Cell, Thanks again, I wonder if i Can Develop VBA Application so it can Push MS Word Lines to Acro Form Fields!. LOL!

  50. LPC says:

    KHK,

    Can I ask a question and forgive me if this question has been answered.
    I have an application form for a company. I want to automate the prefilling in of this form.
    Is there a way of finding out the field names found in that form?
    Thanks in advance.

    LPC

  51. Karl Heinz Kremer says:

    LPC – you can run a JavaScript to report all field names, or use the ICA interface from e.g. a VB or VBA application.

  52. Karl Heinz Kremer says:

    Mohammad, what do you mean by “MS Word Lines”? You can have fields that contain multiple lines, is that what you are asking? If so, just go to the Options tab on the field properties dialog and select to allow multiple lines.

  53. Andreas says:

    Hi, is it possible to use value in one of the cells in the excel sheet to populate a specific field in a PDF form? For example, if I want the value from B5 in Field named “Name”?

    I pretty much got jso.getfield and entering the value for my pdf form but I want to use specific cells instead of typing what to populate.

    Thanks,
    Andreas

  54. Chris says:

    Hi Karl,

    The URL below has code that will allow us to find the names of fillable form fields in secured PDF’s, such as in IRS form 8949.

    http://www.excelhero.com/blog/2010/04/excel-acrobat-pdf-form-filler.html

    I found the above URL in this URL
    https://www.excelguru.ca/forums/showthread.php?6994-VBA-interacting-with-PDF

    In my own project I’ve modified their code to loop through all blank fields and place a number in the field and I’ve recorded the field names and numbers in an Excel sheet. Next, I’m going to investigate why the fields I’ve numbered aren’t in numerical order from left to right and top to bottom. If I cannot automate the correct sorting of numbers than I’ll have to do it manually; which at this point I’m up for it as it has taken me +2 weeks to find/figure out how to write to a fillable field (maybe 20-30 hours). I am so relieved. Thanks for your helpful articles which have greatly helped me along my way.

    Cheers,
    Chris

  55. Jay Nguyen says:

    Hi Karl,

    Thanks for posting this.

    Your base code extracts data from two PDF fields (i.e. Text1 and Text2) on the PDF form. Do you know if it’s possible to reference these fields without knowing their names? e.g. by their order on the form?
    The problem I’m having is that I have a form that have several duplicate field names and so wanted to find a way to extract data from the fields in the those fields.

    Your assistance is much appreciated.

    Cheers,
    -Jay

  56. Karl Heinz Kremer says:

    Jay, you can iterate over all form fields. This will visit all fields in the document. You would then of course have to come up with an algorithm that would give you the fields you want to extract data from. Regarding duplicate field names: Fields that share the same name will always have the same content, and they will only show up once when you iterate over all fields. You will however be able to tell that there are multiple instances when you look at the field’s “page” property: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_properties.htm%23TOC_page3bc-32&rhtocid=_6_1_8_31_1_31
    To get the number of fields, use the iso property “numFields” (https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_properties.htm%23TOC_numFieldsbc-33&rhtocid=_6_1_8_23_0_32)

  57. Armando G says:

    This is a great write up and is almost what I am in need of doing. Ultimately, I need a fillable pdf that will write to a specific Excel sheet upon completion of the pdf form. Do you know if there is a way to add a ‘submit’ type button to allow this to run at the pdf side? I just got access to the full Acrobat DC program and am not to familiar with all of the functions.

    Thought I would throw the question out there in hopes of someone more knowledgeable with the Acrobat program having an answer. If even possible.

  58. Karl Heinz Kremer says:

    No, something that like would need to be triggered from the Excel side.

  59. fatma says:

    i can’t find these references
    Dim App As Acrobat.CAcroApp
    Dim PDDoc As Acrobat.CAcroPDDoc
    where can i get them

  60. Bjorn S says:

    I’ve learned a lot today! Thanks!

    I’m wondering, if I don’t want the PDF to close using the avDoc.Close (True) , but rather have the Save As dialog box pop up, what do I do? Changing the True to False doesn’t do it.

  61. Karl Heinz Kremer says:

    Bjorn, if the document was not modified, Acrobat will not offer to save it. You can create your own Save As dialog in VBA and then call the PDDoc.Save() function.

  62. Fernando Silva Carvalho says:

    Hi Karl,

    Thanks for your post!!

    I wonder if you know of a method through VBA to save a PDF document that contains fields, without the fields.

    In this case, the result should be a document identical to the original document, but without the possibility of editing anything. It would be as if it were a printout of the original document.

    Do you know any method for doing this using VBA?

    Very grateful for your help and attention.

  63. Karl Heinz Kremer says:

    Fernando, you can call JavaScript form VBA, and you have access to preflight profiles from within JavaScript, so I would create a preflight profile that removes the fields and then call that from the VBA program via the JSObject. I have samples of how to do that in other posts (even though there is nothing that utilizes preflight at this time). With the documentation, you should be able to figure out how to execute a preflight profile.

  64. Sushil says:

    Hi!
    I need to access the model tree in a 3D PDF via excel VBA. Is it possible.? If yes How?

  65. Sean says:

    Hi Karl,

    I have a hundreds of pdf files in a folder and want to extract individual property which includes file name and number of pages for each pdf file to an excel list. Can you help me to write VBA in excel.

    Thank you.

  66. Karl Heinz Kremer says:

    Sean, that would be something I would have to handle through my consulting business. I provide as much free help as possible, but I still have to make a living, so anything beyond what’s available in my free blog posts would be done through consulting. Feel free to get in touch with me. My email address is on the About page.

  67. Karl Heinz Kremer says:

    As long as you can get access to this information via JavaScript (see the 3D extensions to JavaScript in the API documentation), you should be able to use the JSObject to do that from within JavaScript.

  68. jackie says:

    Hi Karl,

    May I please ask does below line only accept numbers?
    field2.Value = 13 ‘ assign the number 13 to the fields value

    When i put, for example, field2.Value = “name” which is a string i got error 13 type mismatch

    Regards,
    Jackie

  69. schase02 says:

    amazing how ten years later this is still very valid.

    my question. When you set this.
    “Set field2 = jso.getField(“Text2″)”

    How could you then set it to date format (so the date selector shows). I saw in adobe’s DC JS VBA bridge docs that Field SetAction has a ctrigger of “format” but they do not show how to handle that.

  70. Reto says:

    I want read a thumbnail from the first site of a pdf to show in a ms access form.

  71. Karl Heinz Kremer says:

    Reto, you cannot read thumbnail information from the PDF file via the IAC interface.

  72. Karl Heinz Kremer says:

    There is no “date format” field type. The date fields are text fields with a certain validation and keystroke script. You can poke around to see what these scripts are and then use the JSObject to set the respective scripts in your fields.

  73. Karl Heinz Kremer says:

    Jackie, I assume your field has a validation script that only accepts numbers. A generic text field does not care what you assign to it’s value property, but that changes when you add validation scripts.

  74. Karl Heinz Kremer says:

    fatma, you need Adobe Acrobat installed for that, the free Reader is not sufficient.

Leave a Reply

Your email address will not be published. Required fields are marked *