Combine two PDF into one Separate PDF and save in particular path Using VBA

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone,
Here i am trying to combine two PDF sheets using Adobe, where the below code runs perfectly but
Code:
Sub Combine_PDF()
    Dim x, lastrow As Long
    Dim arrayFilePaths() As Variant
    Set app = CreateObject("Acroexch.app")
    
    lastrow = Sheets("Combine_PDF").Cells(Rows.Count, 1).End(xlUp).Row
    For x = 2 To lastrow
        path1 = Cells(x, "A").Value
        path2 = Cells(x, "B").Value
        arrayFilePaths = Array(path1, path2)
        
        Set primaryDoc = CreateObject("AcroExch.PDDoc")
        OK = primaryDoc.Open(arrayFilePaths(0))
        Debug.Print "PRIMARY DOC OPENED & PDDOC SET: " & OK
        
        For arrayIndex = 1 To UBound(arrayFilePaths)
            numPages = primaryDoc.GetNumPages() - 1
            
            Set sourceDoc = CreateObject("AcroExch.PDDoc")
            OK = sourceDoc.Open(arrayFilePaths(arrayIndex))
            Debug.Print "SOURCE DOC OPENED & PDDOC SET: " & OK
            
            numberOfPagesToInsert = sourceDoc.GetNumPages
            
            OK = primaryDoc.InsertPages(numPages, sourceDoc, 0, numberOfPagesToInsert, False)
            Debug.Print "PAGES INSERTED SUCCESSFULLY: " & OK
            
            OK = primaryDoc.Save(PDSaveFull, arrayFilePaths(0))
            Debug.Print "PRIMARYDOC SAVED PROPERLY: " & OK
            
            Set sourceDoc = Nothing
        Next arrayIndex
        
        Set primaryDoc = Nothing
    Next x
    app.Exit
    Set app = Nothing
    MsgBox "DONE"
End Sub

but can anyone suggest me how i can combine two PDF sheets and save that sheet in separate PDF file and in separate path
Is their any possible ways to do that?????
Please do suggest me with this

Regards
Dhruv
 
Last edited:
What do you mean by an 'accessible PDF file'?

Your code pdDoc.Save PDSaveCopy, NewFilename & Cells(i, 2).Value & ".pdf" is using the PDSaveCopy flag, which means "Write a copy of the file into the file." I don't know the effect of that flag.

Try instead pdDoc.Save PDSaveFull, NewFilename & Cells(i, 2).Value & ".pdf"
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,213,520
Messages
6,114,099
Members
448,548
Latest member
harryls

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