Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CombinePDFs"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private msProblem As String
Public Event Status(ByVal sMessage As String)
Public Property Get Problem() As String
Problem = msProblem
End Property
Public Function Combine(ByVal sOutputFile As String, _
ParamArray SourceFiles()) As Boolean
' files will be combined in the order they were added to SourceFiles()
Dim i As Long
Dim nLB As Long
Dim nUB As Long
Dim nRet As VbMsgBoxResult
Dim oOutputPDF As Acrobat.CAcroPDDoc
Dim oInputPDF As Acrobat.CAcroPDDoc
Dim nPagesTo As Long
Dim nPagesFrom As Long
On Error GoTo ERRHANDLER
Combine = False
nLB = LBound(SourceFiles)
nUB = UBound(SourceFiles)
If nUB < nLB Then
Err.Raise vbObjectError + 6001, "Combine", "No files to combine"
Else
Set oOutputPDF = CreateObject("AcroExch.PDDoc")
RaiseEvent Status("Opening " & SourceFiles(nLB))
If Not oOutputPDF.Open(SourceFiles(nLB)) Then
Err.Raise vbObjectError + 6002, "Combine", "Unable to open " & SourceFiles(nLB)
End If
nPagesTo = oOutputPDF.GetNumPages
For i = (nLB + 1) To nUB
Set oInputPDF = CreateObject("AcroExch.PDDoc")
RaiseEvent Status("Opening " & SourceFiles(i))
If Not oInputPDF.Open(SourceFiles(i)) Then
Err.Raise vbObjectError + 6003, "Combine", "Unable to open " & SourceFiles(i)
End If
nPagesFrom = oInputPDF.GetNumPages
RaiseEvent Status("Inserting " & nPagesFrom & " pages from " & SourceFiles(i))
If Not oOutputPDF.InsertPages(nPagesTo - 1, oInputPDF, 0, nPagesFrom, True) Then
Err.Raise vbObjectError + 6004, "Combine", "Unable to add " & SourceFiles(i)
End If
nPagesTo = oOutputPDF.GetNumPages
Set oInputPDF = Nothing
Next i
RaiseEvent Status("Saving " & sOutputFile)
If Not oOutputPDF.Save(PDSaveFull, sOutputFile) Then
Err.Raise vbObjectError + 6005, "Combine", "Unable to save " & sOutputFile
End If
RaiseEvent Status("Closing " & sOutputFile)
Call oOutputPDF.Close
Set oOutputPDF = Nothing
Combine = True
End If
Exit Function
ERRHANDLER:
msProblem = Err.Description
nRet = MsgBox("Error " & Err.Number & ": " & Err.Description, _
vbQuestion + vbRetryCancel, _
App.Title & " - " & Err.Source)
If nRet = vbRetry Then Resume
Combine = False
Set oOutputPDF = Nothing
Set oInputPDF = Nothing
End Function