sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm tinkering with this in an attempt to merge all pdf files in a folder into 1;
It works fine, and in my testing I've specified Log numbers 1 and 2, but I want to be able to merge all files in the folder that have 'Log Number' in the filename and merge them in order, (i.e 1, 2, 3 onwards etc). I guess I would need to add something after this line;
but I don't know how to if anyone can point me in the right direction please?
Code:
Sub MergePDF()
'Relies on the Adobe Acrobat 6.0 Type Library
Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
'Initialize the 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 (ThisWorkbook.Path & "\Contact Logs\Record of Contact - Log Number 1.pdf")
'Do your loop here to open subsequent documents that you want to add
'Do
'Open the source document that will be added to the destination
objCAcroPDDocSource.Open (ThisWorkbook.Path & "\Contact Logs\Record of Contact - Log Number 2.pdf")
If objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
MsgBox "Documents Merged!"
Else
'0 problem
End If
objCAcroPDDocSource.Close
'loop
objCAcroPDDocDestination.Save 1, ThisWorkbook.Path & "\Contact Logs\Record of Contact (Complete).pdf"
objCAcroPDDocDestination.Close
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
End Sub
It works fine, and in my testing I've specified Log numbers 1 and 2, but I want to be able to merge all files in the folder that have 'Log Number' in the filename and merge them in order, (i.e 1, 2, 3 onwards etc). I guess I would need to add something after this line;
Code:
'Do your loop here to open subsequent documents that you want to add
'Do
but I don't know how to if anyone can point me in the right direction please?