• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Creating, Filling and Saving PDFs via VBA

New Here ,
Oct 12, 2021 Oct 12, 2021

Copy link to clipboard

Copied

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

Screenshot 2021-10-12 142100.jpg 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

412

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Hi,

 

Has the PDF been saved before to that specific location?

 

CAn you try using the PDSaveFull option to see if that has any more success.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

LATEST

To start with, check and report the return value from PDDoc.Save. Also put a message if the Open fails. You shouldn't need to guess which line is failing. Also display filenm to check it is what you expect.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines