1

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
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Paulo Zoio
  • 39
  • 1
  • What is `MergePDFs`? • Note your string is wrong and should be `bSuccess = MergePDFs(strPDFs, FolderPath & "\" & Sheets("Análise CC").Range("O4"))` without the extra quotes `"` in the begining and the end. You should get a compile error in this line. • If you ask questions always tell which errors you get and where. – Pᴇʜ Feb 20 '19 at 15:56
  • Hi, Thanks for the comments and correction. MergePDFs is a function to compile 2 or more pdf files. The first argument is a string, which combines the pdf files to compile. In my case, both file names to compile varies with cells D9 and O4 from "Análise CC" sheet. The second argument of this function is also a string with the location to where the compiled pdf should be saved being the name also cell O4 (this compiled file should replace the former one). the error I get is 'Sub or function not defined' for the MergePDFs function...Thanks in advance – Paulo Zoio Feb 20 '19 at 16:40
  • 1
    If you get 'Sub or function not defined' for the `MergePDFs` function, then it either isn't defined or doesn't have the appropriate scope for where you're calling it from. The error message is fairly clear about that. Is it declared as `Private` in another module? – Comintern Feb 20 '19 at 18:16
  • Put this function `MergePDFs` into a module and declare it as `Public`. – Pᴇʜ Feb 21 '19 at 07:54
  • Thanks, once again. Yes, indeed, the function was declared as private in a different module. Now the routine is working but is giving me the message 'Failed to combine all PDFs'. Since I've the Adobe Pro DC installed and the 'Adobe Acrobat 10.0 type library' is checked in VBA's references (adobe.tlb) I supose I should change to adobe.dll but VBA don't allow (message 'can't add a reference to the specified file')... Once again, thanks for the advice – Paulo Zoio Feb 21 '19 at 16:30

0 Answers0