sunilbsrv2k
Board Regular
- Joined
- May 25, 2018
- Messages
- 73
Hi All,
I am sorry for repeating this question, as I had posted it in another thread.
My question is: I have a Listbox, in which the PDf files of a folder is listed.
Below is a program to merge PDFs.
I want this program to take the contents of this Listbox and combine them into one.
Request your help.
Thanks
I am sorry for repeating this question, as I had posted it in another thread.
My question is: I have a Listbox, in which the PDf files of a folder is listed.
Below is a program to merge PDFs.
I want this program to take the contents of this Listbox and combine them into one.
Request your help.
Code:
Sub Main()
Const DestFile As String = "MergedFile.pdf" ' <-- change to suit
Dim MyPath As String, MyFiles As String
Dim a() As String, i As Long, f As String
' Choose the folder or just replace that part by: MyPath = Range("E3")
With Application.FileDialog(msoFileDialogFolderPicker)
'.InitialFileName = "C:\Temp\"
.AllowMultiSelect = False
If .Show = False Then Exit Sub
MyPath = .SelectedItems(1)
DoEvents
End With
' Populate the array a() by PDF file names
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
ReDim a(1 To 2 ^ 14)
f = Dir(MyPath & "*.pdf")
While Len(f)
If StrComp(f, DestFile, vbTextCompare) Then
i = i + 1
a(i) = f
End If
f = Dir()
Wend
' Merge PDFs
If i Then
ReDim Preserve a(1 To i)
MyFiles = Join(a, ",")
Application.StatusBar = "Merging, please wait ..."
Call MergePDFs(MyPath, MyFiles, DestFile)
Application.StatusBar = False
Else
MsgBox "No PDF files found in" & vbLf & MyPath, vbExclamation, "Canceled"
End If
End Sub
Thanks