Skip to main content
Participant
Jan 12, 2017 2:53 PM UTC
Answered

Save open PDF via VBA

Dears,

I have an little problem in controlling Acrobat DC with VBA (Acess 2013).

My Issue: I have an Automaticly opend .pdf Document and I need to save this at an defined location.

I Have activaed the necessary Libarys in Access

My Code:

Sub SavePDf()

Dim AcroApp As Acrobat.CAcroApp

Dim PdDoc As Acrobat.CAcroPDDoc

Dim avdoc As Acrobat.CAcroAVDoc

   Set AcroApp = CreateObject("AcroExch.App")

   Set avdoc = AcroApp.GetActiveDoc

   Set PdDoc = avdoc.GetPDDoc

   WasSaved = PdDoc.Save(PDSaveFull, "C:\Users\ND01132\Documents\Excel")

End Sub

At the Set PDDoc line I get the Runtime Error 91 "Object variable or Wih block not Set" but I dont have any Idea why.

Thanks for your Help !

Regards

This topic is closed to new replies. Start a new post to keep the conversation going.
Karl Heinz  Kremer
Karl Heinz KremerCorrect answer
Community Expert
Mar 21, 2018 7:59 PM UTC

Hi Karl,

I knew that the variable needed to be defined, just wasn't sure defined as what type of variable as I am not as familiar with how to manipulate things outside of Excel using VBA.  I don't see VARIANT_BOOL as an option for defining a variable on my end - is this within a non-default Library in Excel?  I don't just copy and paste code from the web blindly and typically write most of my code from scratch (when working within the realm of Excel) so I would appreciate if you can avoid generalizing and making assumptions.

I've run a very thorough search online and have yet to see VBA code that is capable of saving an already opened PDF file into a user-specified directory.  I'd also like to be able to manipulate the file name when I save.


You cannot program for Acrobat without the Acrobat SDK (which is mainly documentation). You can download the SDK from Adobe's web site: Adobe - Acrobat Developer Center | Adobe Developer Connection

You can access the documentation for the PDDoc.Save() function here: Acrobat DC SDK Documentation

The documentation does show what type is returned by the Save() function. 

19 replies

Participant
Jul 5, 2021 11:04 AM UTC

How to  replace a PDF page particularly from a PDF deck of 10 pages or so......

Can someone help me on this..

Thanks

Translate
Participant
Jan 7, 2020 7:57 PM UTC

Hello Karl,

Thank you for great help.

 

Can you please advise if it is possible to save a file as a non accisible pdf file?

 

At the moment I use this line:

pdDoc.Save PDSaveCopy, NewFilename & "\" & Sh7.Cells(i + 12, 2).Value & ".pdf"

 

Much appreciated.

Ilan

Translate
Bernd Alheit
Community Expert
Community Expert
Jan 7, 2020 9:02 PM UTC

What does you mean with "non accisible pdf" ?

Translate
Participant
Jan 7, 2020 9:17 PM UTC

appologize, I ment accessible (i.e. cannot change the content of the box through the filled boxes)

 

Thanks.

Translate
Karl Heinz  Kremer
Community Expert
Community Expert
Jan 12, 2017 3:32 PM UTC

This should work. Are you sure you have an open document? You can add a test to see if the AcroApp.GetActiveDoc returns a valid document:

  Set AcroApp = CreateObject("AcroExch.App")

  Set avdoc = AcroApp.GetActiveDoc

  If Not (avdoc Is Nothing) Then

    Set PdDoc = avdoc.GetPDDoc

    WasSaved = PdDoc.Save(PDSaveFull, "C:\Users\ND01132\Documents\Excel")

  End If

Translate
Participant
Jan 12, 2017 3:37 PM UTC

Thats it ! Much thanks for your fast reply Karl Heinz

Translate