saving pdfs in a specific folder post split

ali1985

New Member
Joined
Dec 14, 2019
Messages
18
Office Version
  1. 2016
Hi,

I have a code to split the pdf pages. Now i want to save all the individual pdfs post split in a specific location.

VBA Code:
Sub Main()
  Dim PDDoc As Acrobat.CAcroPDDoc, newPDF As Acrobat.CAcroPDDoc
  Dim PDPage As Acrobat.CAcroPDPage
  Dim thePDF As String, PNum As Long
  Dim f As String, i As Integer, Result As Variant, NewName As String
 
  f = ThisWorkbook.Path & "\"
  thePDF = f & "PaySlips.pdf"
 
  Set PDDoc = CreateObject("AcroExch.pdDoc")
  Result = PDDoc.Open(thePDF)
  If Not Result Then
    MsgBox "Can't open file: " & thePDF
    Exit Sub
  End If
 
  '...
  PNum = PDDoc.GetNumPages
 
  For i = 0 To PNum - 1
    Set newPDF = CreateObject("AcroExch.pdDoc")
    newPDF.Create
    NewName = f & " Page_" & i & "_of_" & PNum & ".pdf"
    newPDF.InsertPages -1, PDDoc, i, 1, 0
    newPDF.Save 1, NewName
    newPDF.Close
    Set newPDF = Nothing
  Next i
End Sub

I believe this line should be changed.......newPDF.Save 1, NewName
any help on this would be appreciated
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The files are stored in the same folder where you have the file with the macro, that is specified in this line:
f = ThisWorkbook.Path & "\"

If you want to specify a folder, it can be like this:

f = "C:\folder\pdf\"
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,392
Members
449,445
Latest member
JJFabEngineering

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