Split PDF Using Excel VBA

Shinod

New Member
Joined
Jun 29, 2022
Messages
38
Office Version
  1. 2019
Platform
  1. Windows
Dear Excel VBA Experts,

I have a pdf file with 20 Pages. Is there any Excel VBA to split each page and rename each page starting from 1001 and ending 1020?

Thanks in Advance
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi Shinod
you can't handle PDF file with VBA alone, you need third party software. Here's an example using PDFTK Builder Enhanced Portable, you can find it here
VBA Code:
Sub SplitPDFtk()
'https://www.mrexcel.com/board/threads/split-pdf-using-excel-vba.1225438/
    
Dim SourceFile      As String, DestFile As String
Dim strParam        As String, RetVal As String, PDFtk As String
Dim i               As Integer
    
PDFtk = "C:\PortableApps\PDFTKBuilderPortable\App\pdftkbuilder\pdftk.exe "        '<<===== ADJUST the Path
SourceFile = "C:\Users\Sequoyah\Desktop\Forum\Foxtrot.pdf"        '<<===== ADJUST the Path and the source File name

Application.ScreenUpdating = False

For i = 1 To 20
    
    DestFile = "C:\Users\Sequoyah\Desktop\Forum\" & "10" & Format(i, "00") & ".pdf"        ''<<===== ADJUST the Path
    
    strParam = SourceFile & " cat " & i & "-" & i & " output " & DestFile
    
    RetVal = Shell(PDFtk & strParam, 0)
    
Next i

Application.ScreenUpdating = True

MsgBox "Done.", vbInformation

End Sub
 
Upvote 0
Hi Shinod
you can't handle PDF file with VBA alone, you need third party software. Here's an example using PDFTK Builder Enhanced Portable, you can find it here
VBA Code:
Sub SplitPDFtk()
'https://www.mrexcel.com/board/threads/split-pdf-using-excel-vba.1225438/
   
Dim SourceFile      As String, DestFile As String
Dim strParam        As String, RetVal As String, PDFtk As String
Dim i               As Integer
   
PDFtk = "C:\PortableApps\PDFTKBuilderPortable\App\pdftkbuilder\pdftk.exe "        '<<===== ADJUST the Path
SourceFile = "C:\Users\Sequoyah\Desktop\Forum\Foxtrot.pdf"        '<<===== ADJUST the Path and the source File name

Application.ScreenUpdating = False

For i = 1 To 20
   
    DestFile = "C:\Users\Sequoyah\Desktop\Forum\" & "10" & Format(i, "00") & ".pdf"        ''<<===== ADJUST the Path
   
    strParam = SourceFile & " cat " & i & "-" & i & " output " & DestFile
   
    RetVal = Shell(PDFtk & strParam, 0)
   
Next i

Application.ScreenUpdating = True

MsgBox "Done.", vbInformation

End Sub
Hi, can you tell me in case I have so many files to split, And I call the part file in column A, and want to split the file by each part file in that column A, how do I edit this code? . (I wrote the code that calls the part file from the directory) but I still don't know how to edit the above code so that it runs separate file by part file in column A. Can you help me with this?
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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