merging pdf files in vba

693 Views Asked by At

I have a sub-routine to print into pdf an "Análise CC" excel sheet which is saved in a folder with a file name varying according to the print I want to perform. So far so good.

Then, I'm developing another sub-routine to compile that former pdf file with another pdf file which is located in the same folder. I'm not able to make MergePDFs function to work. what am I doing wrong? Code below. Thanks!

Sub ExportAsPDF()
    Dim FolderPath As String     
    FolderPath = "C:\Users\DMM\Certificados"

    'Sheets(Array("Análise CC", "QR Code")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderPath & "\" & Sheets("Análise CC").Range("O4"), _
      openafterpublish:=False, ignoreprintareas:=False

    MsgBox "All PDF's have been successfully exported." 
End Sub


Sub Combine_PDFs()
    Dim strPDFs(0 To 1) As String
    Dim bSuccess As Boolean
    Dim FolderPath As String

    FolderPath = "C:\Users\ITG-0720\OneDrive - INSTITUTO TECNOLOGICO DO GAS\ITG\DMM\Certificados"

    strPDFs(0) = FolderPath & "\" & Sheets("Análise CC").Range("D9")
    strPDFs(1) = FolderPath & "\" & Sheets("Análise CC").Range("O4")

    bSuccess = MergePDFs(strPDFs, "FolderPath & "\" & Sheets("Análise CC").Range("O4")")

    If bSuccess = False Then MsgBox "Failed to combine all PDFs", vbCritical, "Failed to Merge PDFs"
End Sub
0

There are 0 best solutions below