Split PDF file and save the new files (VBA)

drom

Active Member
Joined
Mar 20, 2005
Messages
487
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007
Hi and Thanks in advance!


I am working with many PDF files.
Files with pages between 4 and 250
  • For this eg, (MasterPDFFile.PDF with 200 pages)
I am using VBA to find a especific key in these files (No problem, I can do that)
My next step is once I now in one PDF file
  • Page 1 to 3 belongs to a Customer named Peter (easy)
  • Page 4 to 21 belongs to a customer name Frank (easy)
I would line to SPLIT this MasterPDFFile.PDF from Excel, VBA in different small PDF files lg:
  • Save a PDF file as Peter.PDF containing pages from 1 to 3 of the original PDF files (the one that keeps 200 pages for this eg: MasterPDFFile.PDF)
  • Save a PDF file as Frank.PDFcontaining pages from 4 to 21 (so just save the pages for this customer)
    • (I know how to locate using VBA and creating a array the pages I need and the names I am going to use when saving the new divided PDF files)
But I do not know how to split a PDF file from Excel, VBA
  • Maeby is not possible (who knows)
  • I can open the PDF file using Word from (Excel, VBA), but Word does not keep the PDF formatting and page numbers, the way I need
  • This is why I am asking to SPLIT a PDF in X files file from Excel VBA
If I can do this (At present I cant)
  • I will send the created files through Outlook ( Easy)
Thanks again !
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,718
You could split the PDF files by running 'cat' commands of the PDFtk Server tool from VBA. The cat commands for your example should be:

pdftk "C:\folder\path\MasterPDFFile.PDF" cat 1-3 output "C:\folder\path\Peter.PDF"
pdftk "C:\folder\path\MasterPDFFile.PDF" cat 4-21 output "C:\folder\path\Frank.PDF"

The code at Spliting pdf file by Mb size shows how to run PDFtk commands from VBA, specifically the 'command' string and the Wsh.Run command, 0, True line.
 
Upvote 0
Solution

Forum statistics

Threads
1,186,997
Messages
5,961,009
Members
438,514
Latest member
AngSP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top