MsgBox "Cannot save the modified document" If Part1Document.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False Then If Part1Document.InsertPages(numPages - 1, Part2Document,Ġ, Part2Document.GetNumPages(), True) = False Then ' Insert the pages of Part2 after the end of Part1 Set Part2Document = CreateObject("AcroExch.PDDoc") Set Part1Document = CreateObject("AcroExch.PDDoc") Set AcroApp = CreateObject("AcroExch.App") I’ll present the whole program first, and will then explain the different parts.
Let’s start with something simple – let’s combine two PDF documents and save the result as a new document. Of course, before we do that, we need to decide what our button is actually supposed to trigger.
Now we can add code that references the Acrobat objects to our button handler. This is done on the Excel Options dialog, under the Popular category: Once installed, you need to add the “Developer” tab to the ribbon. This is different than all the versions up to 2007.
When you install Office 2007 or Excel 2007, make sure that you select the Visual Basic Editor component, otherwise you will not be able to write VBA code. As long as you have a version of Acrobat that is compatible with the version of VBA that you are using, you should be able to follow along without any problems. For the purpose of this document, I will use MS Excel 2007 and Adobe Acrobat 9 Pro. To learn more about what the differences are, see the IAC Developer Guide. What I’m presenting here is valid for the Adobe Acrobat, Reader only supports a small subset of features. You may have noticed that I always talk about “Adobe Acrobat”, and not the “Adobe Reader”. Let’s get the party startedĪs I mentioned before, regardless of how we want to remote control Adobe Acrobat from VB, we need to establish a connection to it’s COM object (or OLE server).
The latter case still requires that your program first establishes a connection to Acrobat via IAC. You can either use the “normal” IAC (Inter Application Communication) interface, which is basically a COM object that your program loads and uses to communicate with Acrobat, or you can use the VB/JavaScript bridge, which allows access to Acrobat’s JavaScript DOM. One is more direct than the other, but both require the same mechanism to get things started… There are two ways your program can interact with Acrobat. In order to find the documents I’ve listed above, you need to expand the tree on the left side of the window for the “JavaScript” and “Acrobat Interapplication Communication” nodes. Developing Acrobat Applications Using JavaScript (2.7MB PDF document)Īll of these documents can also be accessed via Adobe’s online documentation system.JavaScript for Acrobat API Reference – Version 8 (7.5MB PDF document).If you want to utilize the VB/JavaScript bridge, you also should read the JavaScript related documents: Interapplication Communication API Reference (2.3MB PDF Document).Developing Applications Using Interapplication Communication (510KB PDF Document).There are (at least) two documents that are required reading if you want to use Acrobat from within your VBA code: Before you read any further, click on this link and take a look at what they have available. ResourcesĪll this information is available in one form or another in Adobe’s SDK documentation. It’s up to you to fill in all the missing details (e.g. I only use the samples to demonstrate general methods. It does help that I’ve programmed in many (make that a capital ‘M’ Many) programming languages, and at the end most of them share enough characteristics that once you know one, you know all of them… But still, don’t consider my VB programs to be at an expert level. All I know about VB is from googling a few things and looking at sample code. So keep the comments coming.īefore we get too deep into this, let me say this: I am not a VBA expert. I will only discuss the basics, but I’m open for suggestions about what part to discuss next. MS Excel via VBA? I’ll try to give an introduction into that subject in this document.
Here is another topic that comes up every now and then: How can I “talk” to Adobe Acrobat from e.g.
The comments are closed here, so if you want to comment, you have to head over to Please visit the same post on my business site.