B.Cap
B.Cap

Reputation: 191

PDDoc.Save Adobe Acrobat method not working in Excel VBA

Our office runs Arobat DC Pro and Excel 2016, we have been using the code below (scaled down version) in Excel VBA for years to save active Adobe PDF documents (that is, the open PDF doc that most recently had focus).

Since recently upgrading Arobat DC Pro to a newer version, the Acrobat PDDoc.Save method no longer works. It does not throw an error, it just doesn't save the active PDF.

I have had our IT dept. do an uninstall/reinstall of Acrobat PRO on a couple of computers but code still does not work.

Note, the Adobe Acrobat reference library is selected in VBA.

Any suggestions on how to fix?

Sub SaveActivePDF()

Dim AcroApp As Acrobat.CAcroApp
Dim PdDoc As Acrobat.CAcroPDDoc
Dim avdoc As Acrobat.CAcroAVDoc

Dim boolWasSaved As Boolean

Set AcroApp = CreateObject("AcroExch.App")
Set avdoc = AcroApp.GetActiveDoc
Set PdDoc = avdoc.GetPDDoc

DayTime = Format(Now, "yymmddhmmss")
Username = Environ("USERNAME")

PdfNewPath = "C:\Users\" & Username & "\Desktop\TEST PDF " & DayTime & ".pdf"

boolWasSaved = PDDoc.Save(PDSaveFull, PdfNewPath)   '<-- NOT WORKING 

If boolWasSaved = True Then
        MsgBox "PDF WAS SAVED!"
    Else: MsgBox "ERROR - PDF not saved"
End If

End Sub

Upvotes: 1

Views: 4929

Answers (2)

GgO
GgO

Reputation: 1

VBA idle->press "F2"-> search "AcroPDDoc"->locate its method "Save"

Function Save(nType As Integer, sFullPath As String) As Boolean

In Adobe's acrobatsdk_iacguide.pdf, description of Parameter nType is a little bit confusing. Not sure what integer is for PDSaveFull

nType is a logical OR of one or more of the following flags: PDSaveIncremental — Write changes only, not the complete file. This will always result in a larger file, even if objects have been deleted.

PDSaveFull — Write the entire file to the filename specified by szFullPath.

PDSaveCopy — Write a copy of the file into the file specified by szFullPath, but keep using the old file. This flag can only be specified if PDSaveFull is also used.

PDSaveCollectGarbage — Remove unreferenced objects; this often reduces the file size, and its usage is encouraged. This flag can only be specified if PDSaveFull is also used.

PDSaveLinearized — Save the file optimized for the web, providing hint tables. This allows the PDF file to be byte-served. This flag can only be specified if PDSaveFull is also used.

Upvotes: 0

B.Cap
B.Cap

Reputation: 191

For the record, access to the Acrobat library was blocked by sofware updates that changed default settings.

The issue was resolved as follows: Open any PDF > Edit > Preferences > Security (Enhanced) > ** UNCHECK ** check box "Enable Protected Mode at startup (Preview)" > exit all PDFs.

Upvotes: 4

Related Questions