Combined New Version of PDF to Old Version

mielkew

New Member
Joined
Sep 14, 2015
Messages
21
I have hundreds of drawings needed to insert the new version from an old file of the same drawing number, I can list both files in Column A and Column B respectively for each drawing.

Anyone can point me in the right direction to come up with a VBA code, I'm trying to modify the below, but somehow getting an error

Old Version File PathNew Version File Path
H:\Drawing-01 Rev C00.pdfH:\New Version\Drawing-01 Rev C00.pdf
H:\Drawing-02 Rev C00.pdfH:\New Version\Drawing-02 Rev C00.pdf
H:\Drawing-03 Rev C00.pdfH:\New Version\Drawing-03 Rev C00.pdf
H:\Drawing-04 Rev C00.pdfH:\New Version\Drawing-04 Rev C00.pdf

VBA Code:
Public Sub Merge_PDFs()

    Dim PDFfiles As Variant
    Dim i As Long
    Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
    Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
        
    With ActiveSheet
        PDFfiles = .Range("A2", .Cells(.Rows.Count, "C").End(xlUp)).Value
    End With
    
    'Create Acrobat API objects
    
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    
    'Loop through rows, open PDF file in column A, open and insert PDF file in column B, save as PDF file in column C
    
    For i = 1 To UBound(PDFfiles)
        objCAcroPDDocDestination.Open PDFfiles(i, 1)
        objCAcroPDDocSource.Open PDFfiles(i, 2)
        If Not objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
            MsgBox "Error merging" & vbCrLf & PDFfiles(i, 1) & vbCrLf & "and" & vbCrLf & PDFfiles(i, 2), vbExclamation
        End If
        objCAcroPDDocSource.Close
        objCAcroPDDocDestination.Save 1, PDFfiles(i, 3)
        objCAcroPDDocDestination.Close
    Next
    
    Set objCAcroPDDocSource = Nothing
    Set objCAcroPDDocDestination = Nothing

    MsgBox "Done"
    
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi,
Where is your code giving error? You did not provide information.
I don't have a chance to try your code.
-Acrobat Pro version must be installed for the code to work.
- Column C is not visible in the picture you posted. According to the code, the name of the merged pdf should be written in column C.
(What I wrote has been translated from Turkish to English with Google Translate.)
 
Upvote 0
Hi mielkew,
as @veyselemre observed you must have the Acrobat Pro version (not the free Reader) and you must add the reference to Adobe Acrobat xx.00 Type Library (where xx varies depending on the Acrobat version installed) via Tools -> References in the VBA editor. Then you should just copy column B to column C. In order to avoid unpleasant surprises make a backup copy of the files contained in the folders before trying.
 
Upvote 0
Hi,
Where is your code giving error? You did not provide information.
I don't have a chance to try your code.
-Acrobat Pro version must be installed for the code to work.
- Column C is not visible in the picture you posted. According to the code, the name of the merged pdf should be written in column C.
(What I wrote has been translated from Turkish to English with Google Translate.)
I guess I am getting an error because they both have the same pdf filename, I am new with VBA code, is it possible to open the new drawing version then insert the old version base on cell A and B file path then save the new version having both the New version as 1st Page and Old version as 2nd page in the same folder location of the new version then loop through all the pdf files listed in column A & B. This will save hundreds of times by doing it manually.:( Opening one pdf then dgrag and drop the new version, can this be even done in VBA? Appreciate anyone input.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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