I am currently writing a macro that takes numbers form an excel index. Then finds the PDF file with the same name and combines them into 1 PDF file.
But I am having trouble getting the part that combines the files to work and I cannot find out why it should not work I have my references set correctly.
This is the part that I am having trouble with.
Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
Dim i As Integer
Dim iFailed As Integer
Dim strSaveAs As String
Dim MergePDFs As Boolean
strSaveAs = GetNewFolder & "\" & TxtNewFileName.Text
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.Open (thisarray(LBound(thisarray))) '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(thisarray) + 1 To UBound(thisarray)
If objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
MergePDFs = True
Else
'failed to merge one of the PDFs
iFailed = iFailed + 1
End If
objCAcroPDDocSource.Close
Next i
objCAcroPDDocDestination.Save 1, strSaveAs 'Save it as a new name
objCAcroPDDocDestination.Close
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
NoAcrobat:
If iFailed <> 0 Then
MergePDFs = False
End If
On Error GoTo 0
I hope this is enough information. I don't really want to post the entire code because it is very long. Thank you for your effort.
Please, add this line
objCAcroPDDocSource.Open (thisarray(i))
after
For i = LBound(thisarray) + 1 To UBound(thisarray)
You did not open the Source
file and it is nothing to be merged...