VBA to combine supported files in a folder into 1 pdf
I'm wondering if there's a VBA function that allows me to replicate the "Combine Supported files in Acrobat" function when right clicking on a folder in Windows Explorer.
I have a folder where I need all the files in that 1 folder combined into a pdf document. And I have about 200 of these folders. I've gotten as far as using the file system object to crawl through the folder structure and it looks like the only way to do this is to open the file's specific application in VBA and use that application's export/save as function to save as pdf, then combine all the files into the overall pdf. Is there a more efficient way of doing this? Luckily, I only need to combine word, excel and pdf files.
Basically, the code/pseudo-code looks like this:
Sub ConvertToPDF()
Dim path As String
path = "c:\drive"
Dim adobe As AcroApp
Set adobe = New AcroApp
Dim FSO As Scripting.FileSystemObject
Dim folder1 As Scripting.folder
Dim folder2 As Scripting.folder
Dim file As Scripting.file
Dim binder as Acrobat.AcroPDDoc
Dim tempPDF as Acrobat.AcroPDDoc
Set FSO = New Scripting.FileSystemObject
Set folder1 = FSO.GetFolder(path)
For Each folder2 In folder1.SubFolders
'create a blank pdf
Set binder = new AcroPDDoc
binder.create()
For Each file In folder2
Select Case file.Type
Case "Microsoft Excel Worksheet"
ConvertWordtoPDF file.path, file.Name
Case "Microsoft Word Document"
ConvertExceltoPDF file.path, file.Name
Case "PDF File"
Case Else
MsgBox "Cannot convert " & file.Name
End Select
'Pseudo Code for Now
'open each pdf in the folder
'insert the opened pdf into the blank pdf
Next file
'save binder file
Next folder2
End Sub
Sub ConvertWordtoPDF(path As String, filename As String)
'open up Word application with the filename and export to pdf
End Sub
Sub ConvertExceltoPDF(path As String, filename As String)
'open up Excel application with the filename and export to pdf
End Sub
Posted Jul 21, 2017, 9:35 PM UTC