Creating, Filling and Saving PDFs via VBA
Hello, I am having some issues with a VBA script. I am fairly new to this so there may be some issues I don't see.
My main issue right now is that the forms are being filled but the save function is not working. I can see the forms are being filled but closed without saving. ultimately leaving me with blank forms.
I downloaded and installed the SDK as per the page I found but maybe I don't have the right ones enabled or installed.
Also my script is a mishmash of a ton of other threads I've found online so maybe its faulty from its base level.
Thanks in advance!
Sub FillDocuments()
'Step 1 Define Variables
Dim FileNm, gApp, avDoc, pdDoc, jso
Dim i As Integer
Dim Path As String
Dim ProjectName As String
Dim EQID As String
Dim SubNum As String
Dim FileName As String
Dim QCForm As String
'LOOP Start
i = 2
Do
'Step 2 Define Data from Excel Sheet
ProjectName = ThisWorkbook.Worksheets("EQData").Cells(i, 1).Value
EQID = ThisWorkbook.Worksheets("EQData").Cells(i, 2).Value
SubNum = ThisWorkbook.Worksheets("EQData").Cells(i, 3).Value
QCForm = ThisWorkbook.Worksheets("EQData").Cells(i, 4).Value
'Step 3 Define Data For Files Location
FileName = SubNum & " " & EQID & " " & QCForm & ".pdf"
Path = ThisWorkbook.Path
FileNm = Path & "\" & FileName
'Step 5 Open and Update Fields In Each Form
Set gApp = CreateObject("AcroExch.app")
Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(FileNm, "") = True Then
Set pdDoc = avDoc.GetPDDoc()
avDoc.BringToFront
Set jso = pdDoc.GetJSObject
jso.getfield("ProjectName").Value = ProjectName
jso.getfield("FirmwareV").Value = "Test"
jso.getfield("SubName&Num").Value = "Test"
jso.getfield("Location").Value = "Test"
'Step 6 Save changes to the PDF document (I assume this is where the issue is)
pdDoc.Save PDSaveIncremental, FileNm
pdDoc.Close
End If
'Close the PDF; the True parameter prevents the Save As dialog from showing
avDoc.Close (False)
'Some cleaning
Set gApp = Nothing
Set avDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing
'Iterate down the list of documents
i = i + 1
Loop While ThisWorkbook.Worksheets("EQData").Cells(i, 4).Value <> ""
End Sub
