VBA & Macro Problems

How to Merge Multiple PDF Files Using Excel VBA

Jason MillerJason Miller Nov 5, 2026 869 views

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.

How to Merge a Variable Number of PDF Files with Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Enable the Acrobat Library Reference

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.

2
Organize Your Worksheet Data

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.

3
Write the Looping Logic

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.

4
Initialize the AcroExch Objects

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.

5
Insert Pages and Save

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.

Automate PDF Merging Using Excel VBA and Acrobat Pro API
Requires Acrobat Pro API: The AcroExch.PDDoc object and InsertPages method will fail if you only have Adobe Reader installed. You must have a paid version of Adobe Acrobat to utilize these specific automation tools.
Free Microsoft Office alternative

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. 1. Download and Install WPS Office: Get WPS Office from the official website and open the application.
  2. 2. Open the PDF Toolkit: Navigate to the 'PDF' tab on the main dashboard and select the 'Merge PDF' tool.
  3. 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.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .xlsm)Built-in PDF toolkit allows you to easily merge, split, and edit PDFs without writing VBA codeLightweight application that consolidates Word, Excel, PowerPoint, and PDF tools in one tabbed interfaceFree to download and use with advanced tools for professionals
microsoft office alternative - wps office

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.