It’s easy to copy and paste a macro like this, but it’s harder make one on your own. Make powerful macros with our free VBA Developer Kit Close Set objCAcroPDDocSource = Nothing Set objCAcroPDDocDestination = Nothing NoAcrobat : If iFailed 0 Then MergePDFs = False End If On Error GoTo 0 End Function Save 1, strSaveAs 'Save it as a new name objCAcroPDDocDestination. GetNumPages, 0 ) Then MergePDFs = True Else 'failed to merge one of the PDFs iFailed = iFailed + 1 End If objCAcroPDDocSource. GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource. Open ( arrFiles ( i )) If objCAcroPDDocDestination. Open ( arrFiles ( LBound ( arrFiles ))) 'open the first file 'Open each subsequent PDF that you want to add to the original 'Open the source document that will be added to the destination For i = LBound ( arrFiles ) + 1 To UBound ( arrFiles ) objCAcroPDDocSource. CAcroPDDoc Dim i As Integer Dim iFailed As Integer On Error GoTo NoAcrobat : 'Initialize the Acrobat objects Set objCAcroPDDocDestination = CreateObject ( "AcroExch.PDDoc" ) Set objCAcroPDDocSource = CreateObject ( "AcroExch.PDDoc" ) 'Open Destination, all other documents will be added to this and saved with 'a new filename objCAcroPDDocDestination. CAcroPDDoc Dim objCAcroPDDocSource As Acrobat. In other words,- ' Adobe Reader will not work.- '- Dim objCAcroPDDocDestination As Acrobat. This has been tested with Acrobat 6.0 and 10.0.- '-CAUTION: This function won't work unless you have the full Adobe Acrobat. Private Function MergePDFs ( arrFiles () As String, strSaveAs As String ) As Boolean '- '-PROGRAM: MergePDFs- '-DEVELOPER: Ryan Wells ()- '-DATE: 09/2017- '-DESCRIPTION: This function uses Adobe Acrobat (won't work with just the Reader!) to- '- combine PDFs into one PDF and save the new PDF with its own file name.- '-INPUT: The function requires two arguments.- '- 1) arrFiles is an array of strings containing the full path to each PDF you want to- '- combine in the order you want them combined.- '- 2) strSaveAs is a string containing the full path you want to save the new PDF as.- '-REQUIREMENTS: 1) Must add a reference to "Adobe Acrobat X.0 Type Library" or "Acrobat"- '- under Tools > References.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |