Split PDF file and save the new files (VBA)

drom

Well-known Member
Joined
Mar 20, 2005
Messages
527
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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
Back
Top