Hi everyone,
I adapted a VBA code found on the message board to merge 6 different PDF files into one PDF, but it is not working and I am lost as to where to look.
I have Adobe Acrobat DC installed but the files are not merging and I do not get an error message, so this is probably something stupid. All the pdf files are saved to the same folder. The file called "myPDFFile1.pdf" is the PDF I wish to merge the other documents into. I have 2 different codes which are below:
and
The code runs and I get the pop-up message, but not a merged file.
Thanks for the help.
Kat
I adapted a VBA code found on the message board to merge 6 different PDF files into one PDF, but it is not working and I am lost as to where to look.
I have Adobe Acrobat DC installed but the files are not merging and I do not get an error message, so this is probably something stupid. All the pdf files are saved to the same folder. The file called "myPDFFile1.pdf" is the PDF I wish to merge the other documents into. I have 2 different codes which are below:
VBA Code:
Sub mainCreateFile()
Dim myCol As Collection
Dim strFile As String
Dim inputDirectoryToScanForFile As String
Dim primaryFile As String
Set myCol = New Collection
primaryFile = "C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile1.pdf"
myCol.Add primaryFile
inputDirectoryToScanForFile = "C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\"
strFile = Dir(inputDirectoryToScanForFile & "*.pdf")
Do While strFile <> ""
myCol.Add strFile
strFile = Dir
Loop
End Sub
and
VBA Code:
Sub mainmerge()
Dim arrayFilePaths() As Variant
Set app = CreateObject("Acroexch.app")
arrayFilePaths = Array("C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile2.pdf", _
"C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile3.pdf", _
"C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile4.pdf", _
"C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile5.pdf", _
"C:\Users\KH\OneDrive - CCMI\Desktop\EXPOSURES\myPDFFile6.pdf")
Set primaryDoc = CreateObject("AcroExch.PDDoc")
OK = primaryDoc.Open(arrayFilePaths(0))
Debug.Print "PRIMARY DOC OPENED & PDDOC SET: " & OK
For arrayIndex = 1 To UBound(arrayFilePaths)
numPages = primaryDoc.GetNumPages() - 1
Set sourceDoc = CreateObject("AcroExch.PDDoc")
OK = sourceDoc.Open(arrayFilePaths(arrayIndex))
Debug.Print "SOURCE DOC OPENED & PDDOC SET: " & OK
numberOfPagesToInsert = sourceDoc.GetNumPages
OK = primaryDoc.InsertPages(numPages, sourceDoc, 0, numberOfPagesToInsert, False)
Debug.Print "PAGES INSERTED SUCCESSFULLY: " & OK
OK = primaryDoc.Save(PDSaveFull, arrayFilePaths(0))
Debug.Print "PRIMARYDOC SAVED PROPERLY: " & OK
Set sourceDoc = Nothing
Next arrayIndex
Set primaryDoc = Nothing
app.Exit
Set app = Nothing
MsgBox "The Use Log is complete"
End Sub
The code runs and I get the pop-up message, but not a merged file.
Thanks for the help.
Kat