title: Excel values to PDF form fields
body: <p>objJSO.GetField(strField).Value = (strFieldVal)  - That is the line I'm recieving a 'type mismatch' error on.
  I've found the code base from "My Engineering World".  It is an old post.</p>
  
  <p>I'm selecting a static PDF form and trying to write values from an excel doc to the PDF form which contains the same field names.  The excel doc has the field names in column c20-149 with the values for those fields in d20-149.  I'm trying to write the values for those fields into the selected PDF form.</p>
  
  <pre><code>Option Explicit
  </code></pre>
  
  <p>Sub btnToPDF_Click()</p>
  
  <pre><code>Dim objAcroApp As Object
  Dim objAcroAVDoc As Object
  Dim objAcroPDDoc As Object
  Dim objJSO As Object
  Dim fd As Office.FileDialog
  Dim strFile As String
  Dim strField As String
  Dim strFieldVal As String 'Used to hold the field value
  Dim r As Long 'Used to increase row number for strfield name
  
  'Disable screen flickering.
      Application.ScreenUpdating = False
  
  'Choose the Onsite Survey form you want to fill
      Set fd = Application.FileDialog(msoFileDialogFilePicker)
  
      With fd
  
          .AllowMultiSelect = False
  
          .Title = "Please select the On-site survey PDF."
          .Filters.Clear
          .Filters.Add "PDF", "*.PDF"
          '.Filters.Add "All Files", "*.*"
  
      'If the .Show method returns False, the user clicked Cancel.
          If .Show = True Then
              strFile = .SelectedItems(1)
              MsgBox (strFile)
          End If
      End With
  
  'Initialize Acrobat by creating the App object.
      Set objAcroApp = CreateObject("AcroExch.App")
  
  'Check if the object was created.
      If Err.Number &lt;&gt; 0 Then
          MsgBox "Could not create the App object!", vbCritical, "Object error"
          'Release the object and exit.
          Set objAcroApp = Nothing
          Exit Sub
      End If
  
  'Create the AVDoc object.
  Set objAcroAVDoc = CreateObject("AcroExch.AVDoc")
  
      'Check if the object was created.
          If Err.Number &lt;&gt; 0 Then
              MsgBox "Could not create the AVDoc object!", vbCritical, "Object error"
          'Release the objects and exit.
              Set objAcroAVDoc = Nothing
              Set objAcroApp = Nothing
              Exit Sub
          End If
  
      On Error GoTo 0
  
  'Open the PDF file.
      If objAcroAVDoc.Open(strFile, "") = True Then
  
          'Set the PDDoc object.
              Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
  
          'Set the JS Object - Java Script Object.
              Set objJSO = objAcroPDDoc.GetJSObject
  
              On Error GoTo 0
  
          'Fill the form fields.
              For r = 20 To 149
                  strField = Cells(r, 3)
                  strFieldVal = Cells(r, 4)
  
                  objJSO.GetField(strField).Value = CStr(strFieldVal)
  
  
                  If Err.Number &lt;&gt; 0 Then
  
                      'Close the form without saving the changes.
                      objAcroAVDoc.Close True
  
                      'Close the Acrobat application.
                      objAcroApp.Exit
  
                      'Inform the user about the error.
                      MsgBox "The field """ &amp; strField &amp; """ could not be found!", vbCritical, "Field error"
  
                      'Release the objects and exit.
                      Set objJSO = Nothing
                      Set objAcroPDDoc = Nothing
                      Set objAcroAVDoc = Nothing
                      Set objAcroApp = Nothing
                      Exit Sub
  
                  End If
          Next r
  
  
      'Save the form
          objAcroPDDoc.Save 1, strFile
  
      'Close the form without saving the changes.
          'objAcroAVDoc.Close True
  
  
      'Close the Acrobat application.
          objAcroApp.Exit
  
      'Release the objects.
          Set objJSO = Nothing
          Set objAcroPDDoc = Nothing
          Set objAcroAVDoc = Nothing
          Set objAcroApp = Nothing
  
  
  
      'Enable the screen.
          Application.ScreenUpdating = True
  
      'Inform the user that forms were filled.
          MsgBox "All forms were created successfully!", vbInformation, "Finished"
  End If
      MsgBox "Something bad happend :(...."
  </code></pre>
  
  <p>End Sub</p>