0

I am using VBA as a platform to do some PDF manipulation. The issue I am having is that I cannot seem to get the PDF object to save if the PDF object have not been opened. Below is a snippet of the code that inserts pages to the PDF object, and then saves the pdf object. In terms of the code, I have determined that it works since I have tested the save method with the same input with another pdf object and it worked just fine. Can someone help by explaining why it doesn't allow me to save the object?

Thanks!

Dim NewPDF As New Acrobat.AcroPDDoc
Set NewPDF = CreateObject("AcroExch.PDDoc")
If NewPDF.InsertPages(j, OriPDF, j, 1, 0) Then MsgBox "Success"
If NewPDF.Save(PDSaveLinearized, WritePath & "\" & sh.Cells(StartRow + j - 1, i).Value & ".pdf") Then MsgBox "Success"
NewPDF.Close
Set NewPDF = Nothing

When the above code was ran, neither of the success lines worked as expected.

Isa
  • 271
  • 1
  • 6
  • 16

1 Answers1

1

Change line 3 to this...

If NewPDF.InsertPages(-1, OriPDF, j, 1, 0) Then MsgBox "Success" 

The first parameter is the location after which the new pages get inserted but you have no pages because the document is empty so there is no page zero.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • I am trying to find a way to send you messages but I cannot seem to find it anywhere. Is there a good way I can send it to you? I used a workaround at the moment by creating a blank pdf file elsewhere and use that as a template file. But it will be good to understand why it doesn't work as well. Thanks! – Isa Jul 21 '17 at 15:11
  • You can reach me at joel@practicalpdf.com – joelgeraci Jul 21 '17 at 15:49
  • I got the answer from another forum. Apparently, I need to have a line to create the actual PDF object as createobject() only creates the PDDoc object, which is a pointer. I think I got it now! Thanks for your help! – Isa Jul 21 '17 at 16:05
  • Oops, I take that back. Something really really really strange is going on. Let me send you an email. Thanks! – Isa Jul 21 '17 at 16:44