Hello,
I have spent quite a lot of time trying to work my questions out, and have searched the web as best I could for an answer, but alas I am stuck and hope someone here can help me ![Smile]()
I am fairly competent around VBA and for the first time attempted to communicate with another application. This application is Adobe and I wanted to write some code that merged multiple PDFs into one document. I asked this question on a VBA forum and got no replies, so I thought I best to ask here where perhaps people are more familiar with Adobe Acrobat.
My two questions are the following
1.) When you specify the dimensions why is it Acrobat.CAcroApp and Acrobat.CAcroPDDoc? I tried it without the 'C' and it works fine, but all the code I saw on the net set the dimensions this way. I read the Adobe literature and it seems to be something to do Microsoft Visual C++. I have not been formally trained in computer science so there are many gaps in my knowledge. Could some please explain in layman terms what this is about?
2.) Adding a password to the final merged document? I dont know how to do this. I thought there would be a security or password property of the PDDoc object, but there isn't. I have seen sample code in Javascript (which I dont understand) which seems to add passwords to recently formed PDF documents. But I can't find or see anyway to do it using VBA/Adobe. Can anyone advise? Is it even possible to do this in VBA?
Any help would be much appreciated!
Please see below my code (I know its quite crude but I am keeping it simple whilst I learn):
Sub pdftest()
Dim AcroApp As Acrobat.CAcroApp
Dim Part1Document As Acrobat.CAcroPDDoc
Dim Part2Document As Acrobat.CAcroPDDoc
Dim Part3Document As Acrobat.CAcroPDDoc
Dim Part4Document As Acrobat.CAcroPDDoc
Dim Part5Document As Acrobat.CAcroPDDoc
Dim Part6Document As Acrobat.CAcroPDDoc
Dim Part7Document As Acrobat.CAcroPDDoc
Dim numpages As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set Part1Document = CreateObject("AcroExch.PDDoc")
Set Part2Document = CreateObject("AcroExch.PDDoc")
Set Part3Document = CreateObject("AcroExch.PDDoc")
Set Part4Document = CreateObject("AcroExch.PDDoc")
Set Part5Document = CreateObject("AcroExch.PDDoc")
Set Part6Document = CreateObject("AcroExch.PDDoc")
Set Part7Document = CreateObject("AcroExch.PDDoc")
Part1Document.Open ("G:\Clients\weekly\1.pdf")
Part2Document.Open ("G:\Clients\weekly\2.pdf")
Part3Document.Open ("G:\Clients\weekly\3.pdf")
Part4Document.Open ("G:\Clients\weekly\4.pdf")
Part5Document.Open ("G:\Clients\weekly\5.pdf")
Part6Document.Open ("G:\Clients\weekly\6.pdf")
Part7Document.Open ("G:\Clients\weekly\7.pdf")
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part2Document, 0, Part2Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part3Document, 0, Part3Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part4Document, 0, Part4Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part5Document, 0, Part5Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part6Document, 0, Part6Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.InsertPages(numpages - 1, Part7Document, 0, Part7Document.GetNumPages(), True) = False Then
MsgBox ("Error")
End If
numpages = Part1Document.GetNumPages
If Part1Document.Save(PDSaveFull, "G:\Clients\weekly\WeeklyTest.pdf") = True Then
MsgBox ("This has been saved")
End If
Debug.Print numpages
End Sub