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

Save open PDF via VBA

New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

37.0K

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

correct answers 1 Correct answer

Community Expert , Mar 21, 2018 Mar 21, 2018

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. 

Votes

Translate

Translate
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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

Votes

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
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Thats it ! Much thanks for your fast reply Karl Heinz

Votes

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
Guest
Mar 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

Sorry for bumping an old thread, but I get an error when I try to implement this saying that 'WasSaved' needs to be defined.  Am I missing something here?  Would appreciate some help.

Votes

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 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

What you are missing is that the code that was presented by the original poster is not the whole program. The variable "WasSaved" was very likely defined outside of the function scope. This is basic VB/VBA and has nothing to do with the Acrobat SDK. Just add something like this - either inside the sub, or in a global scope:

Dim WasSaved as VARIANT_BOOL

It is never a good idea to copy and paste a solution together from things you find online. You need to understand the code you are pasting in order to be able to adjust it to your specific needs. That's why some people in these forums do not post any code. I do post sample code, but alwayswith the assumption that it's just a sample and not something that should or can be used by just copying it.

Votes

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
Guest
Mar 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

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.

Votes

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 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

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. 

Votes

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
Guest
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

I figured out my own solution to this without using Adobe SDK.  Thank you for your help.

Votes

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
New Here ,
May 11, 2019 May 11, 2019

Copy link to clipboard

Copied

Hi, georgem31582523.

Would you mind sharing your method to save the opened PDF to a new file? Just methodology and the logic is fine. I will figure out the rest on my own.

Thanks so much in advance.

Votes

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 ,
May 12, 2019 May 12, 2019

Copy link to clipboard

Copied

The Acrobat SDK gives documentation which all Acrobat programmers need.

Votes

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
New Here ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Hello.....

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

Can someone help me on this..

Thanks

 

Votes

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 ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

LATEST

Saikumar5FF0, This topic is not about replacing pages. It gets very confusing for everyone if you add unrelated questions, as everyone participating gets all the messages. Please start a new topic. Be sure you have read the Acrobat SDK.

Votes

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
New Here ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

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

Votes

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 ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

What does you mean with "non accisible pdf" ?

Votes

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
New Here ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

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

 

Thanks.

Votes

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 ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

You can set the form fields as read-only or flatten the form fields.

Votes

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
New Here ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Thanks.

I think that I need to flatten the form fields.

 

can I tweak this statement for that purpose?

 

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

 

Thanks.

Votes

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 ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Look for the method flattenPages in the Acrobat Javascript Reference.

Votes

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
New Here ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Thank you, will do.

Votes

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
New Here ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

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

Can someone help me on this..

Thanks

Votes

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