blaksnm
Well-known Member
- Joined
- Dec 15, 2009
- Messages
- 554
- Office Version
- 365
- Platform
- Windows
Hi
There are some PDFs in folder (folder: "C:\!ConsEasy")
I want to pick the ones to be merged
So far I have got the macro below, but when running this it only opens a folder and no PDF-files is visible to pick
Will anyone be so kind to guide me to sucsess here?
Private Sub Merge_PDFs(PDFfolder As String)
Const Q As String = """"
Dim Wsh As Object 'WshShell
Dim inputPDFs As String, outputPDF As String
Dim PDFfile As String
Dim command As String
Dim page As Long
If Right(PDFfolder, 1) <> "\" Then PDFfolder = PDFfolder & "\"
outputPDF = PDFfolder & "All_PDFs_Merged.pdf"
If Dir(outputPDF) <> vbNullString Then Kill outputPDF
page = 1
inputPDFs = ""
Do
PDFfile = Dir(PDFfolder & "Page" & page & ".pdf")
If PDFfile <> vbNullString Then inputPDFs = inputPDFs & Q & PDFfile & Q & " "
page = page + 1
Loop While PDFfile <> vbNullString
'Merge PDFs with cat
command = "CD /D " & Q & PDFfolder & Q & " & PDFtk " & inputPDFs & " cat output " & Q & outputPDF & Q
Set Wsh = CreateObject("WScript.Shell") 'New WshShell
Wsh.Run "cmd /c " & command, 0, True
End Sub
There are some PDFs in folder (folder: "C:\!ConsEasy")
I want to pick the ones to be merged
So far I have got the macro below, but when running this it only opens a folder and no PDF-files is visible to pick
Will anyone be so kind to guide me to sucsess here?
Private Sub Merge_PDFs(PDFfolder As String)
Const Q As String = """"
Dim Wsh As Object 'WshShell
Dim inputPDFs As String, outputPDF As String
Dim PDFfile As String
Dim command As String
Dim page As Long
If Right(PDFfolder, 1) <> "\" Then PDFfolder = PDFfolder & "\"
outputPDF = PDFfolder & "All_PDFs_Merged.pdf"
If Dir(outputPDF) <> vbNullString Then Kill outputPDF
page = 1
inputPDFs = ""
Do
PDFfile = Dir(PDFfolder & "Page" & page & ".pdf")
If PDFfile <> vbNullString Then inputPDFs = inputPDFs & Q & PDFfile & Q & " "
page = page + 1
Loop While PDFfile <> vbNullString
'Merge PDFs with cat
command = "CD /D " & Q & PDFfolder & Q & " & PDFtk " & inputPDFs & " cat output " & Q & outputPDF & Q
Set Wsh = CreateObject("WScript.Shell") 'New WshShell
Wsh.Run "cmd /c " & command, 0, True
End Sub