How to Merge Multiple PDF Files Using Excel VBA
Question details
The user wants to automate the process of grouping and merging multiple PDF files using an Excel VBA macro and Adobe Acrobat Pro.

- Product
- Excel / Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- Merging a dynamic number of source PDF files grouped by specific criteria defined in an Excel worksheet.
- Observed behavior
- The goal is to successfully execute a VBA script that outputs a separate, merged PDF file for each designated group of source PDFs specified in the worksheet rows.
Ensure you have Adobe Acrobat Pro or Standard installed on your computer, as the free Adobe Reader does not support the necessary developer APIs for manipulating PDF files. You will also need to enable the Acrobat Reference library within your Excel VBA editor.
Automate PDF Merging Using Excel VBA and Acrobat Pro API
Leverage Adobe Acrobat's API through Excel VBA to loop through worksheet data, group specific source PDFs, and merge them into designated output files.
This solution relies on the 'AcroExch' object to open, insert, and save PDF pages. Your Excel sheet should be organized with the desired output PDF name in one column and the source PDF file paths in another so the script can group them logically.
Open the VBA Editor by pressing Alt + F11 in Excel. Go to Tools > References, scroll down the list, and check the box for 'Acrobat [Version] Type Library'. Click OK.
Set up your Excel sheet so that Column A contains the desired output filename (e.g., 'Group1.pdf') and Column B contains the full file path of the source PDFs to be merged.
Create a new Module (Insert > Module) and write a VBA loop that reads down the rows. Use an 'If' statement to check when the output filename in Column A changes, signaling the start of a new group.
Within your script, declare and set 'AcroExch.PDDoc' objects for both the base document and the document being inserted. Use the base document to open the first PDF of the group.
For subsequent files in the same group, use the 'InsertPages' method on the base document to append the new pages. Once the group changes, use the 'Save' method to output the merged PDF, close the object, and start the next group.

Looking for an Easier Way to Manage Spreadsheets and PDFs?
While Excel VBA requires complex scripting and expensive third-party software like Adobe Acrobat Pro to manipulate PDFs, WPS Office offers a comprehensive, all-in-one suite. With built-in PDF tools and seamless Microsoft Office compatibility, you can manage your data and documents effortlessly.
- 1. Download and Install WPS Office: Get WPS Office from the official website and open the application.
- 2. Open the PDF Toolkit: Navigate to the 'PDF' tab on the main dashboard and select the 'Merge PDF' tool.
- 3. Combine Your Files: Simply drag and drop the PDFs you want to merge, arrange their order, and click 'Merge' to create your combined document instantly.

Frequently Asked Questions
Why am I getting a 'User-defined type not defined' error in my PDF merge VBA code?
This error typically occurs if you haven't enabled the Adobe Acrobat library reference. In the VBA editor, you must go to Tools > References and check 'Acrobat [Version] Type Library' before running scripts that interact with Acrobat.
Can I use this VBA script with the free Adobe Reader?
No, Adobe Reader does not include the Acrobat API required to manipulate, merge, or save PDF files via automation. You must have Adobe Acrobat Standard or Pro installed on your machine.
Is there a way to merge PDFs in Excel without using VBA?
Excel natively does not have a feature to merge existing PDF files. You would need to use a dedicated PDF editor, an online merging tool, or built-in utilities in alternative suites like WPS Office to combine PDFs manually.
How can I group files automatically in Excel before merging?
You can set up a column with identical output names for source files that belong together. Your VBA code should loop through this column, using an 'If' statement to trigger the merge and save sequence whenever it detects a change in the output name.




