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
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 Path | New Version File Path |
H:\Drawing-01 Rev C00.pdf | H:\New Version\Drawing-01 Rev C00.pdf |
H:\Drawing-02 Rev C00.pdf | H:\New Version\Drawing-02 Rev C00.pdf |
H:\Drawing-03 Rev C00.pdf | H:\New Version\Drawing-03 Rev C00.pdf |
H:\Drawing-04 Rev C00.pdf | H:\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