Here is some code. This isn't the complete code, just the relevant parts. If you need more than this let me know.
The first code isn't really necessary, however, it may be of use to notify if pdftk is not installed so that the code won't error out in such a case.
Code:
If InStr(Environ("Path"), "pdftk") = 0 Then
MsgBox "It appears that PDF tool kit is not installed on this computer. " & _
"Please refer to user guide for instructions on how to install it. " & _
"This program is needed in order to merge pdf files.", vbExclamation + vbOKOnly, "Missing Program PDFtk"
Exit Function
End If
This code uses a variable to store the command line, so if you prefer to insert the command line directly, that would go in the stMergeFiles slot of the code in the shell command. I added "M" to the name to indicate it was the merged version. Then later on the code would remove the M. I'm using a comma separated list for the files to be merged and that is why there is a split function. Using [tt]Chr(34)[/tt] to deal with quote issue.
[tt]stMergeFiles = Chr(34) & CustomSplit(pdfname, ",", 1) & Chr(34) & " " & Chr(34) & CustomSplit(pdfname, ",", 2) & Chr(34) & " cat output " & Chr(34) & Replace(CustomSplit(pdfname, ",", 1), ".pdf", "M.pdf" & Chr(34))[/tt]
On my system, sometimes files would take longer to merge and to prevent the code from continuing, I put a message box to prevent that and then click OK once the black screen of the shell command has closed. If you happen to know how to identify when the shell command is done, then you wouldn't need the message box. I haven't figured that part out.
[tt]Dim stMergeFiles As String
Dim retVal As Variant
[/tt]
Here is the shell command
Code:
retVal = Shell("pdftk " & stMergeFiles, vbMaximizedFocus)
MsgBox "Please wait for pdftk 'BLACK SCREEN' to close and then press OK to continue." & vbCrLf & vbCrLf & "Note:Big files may take longer to merge. Please be patient", vbOKOnly + vbExclamation, "Files Merged"
DoEvents
Here is the custom split function
Code:
Public Function CustomSplit(strField As String, delim As String, intPosition As Variant) As String
If InStr(strField, delim) > 0 Then
On Error GoTo errcheck
CustomSplit = Split(strField, delim)(intPosition)
End If
errcheck:
'Debug.Print Err.Number & Err.Description
End Function