Posts Tagged ‘Excel VBA PDF Printing’

Don’t know if this will ever be needed again, but it was useful to me once, so I pass it along…

The following code loops through every file in a specified folder and prints every PDF that it finds:

'Use of FileSystemObject requires a reference to "Microsoft Scripting Runtime"
Dim objFSO As Scripting.FileSystemObject
Dim objFld As Scripting.Folder
Dim objFil As Scripting.file

'The ADOBE_PATH constant assumes a Win7 PC; your actual location may be different
Const ADOBE_PATH As String = "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"
Const FILE_PATH As String = "C:\MyInvoiceFolder\"
Const FILE_EXT As String = "PDF"

Set objFSO = New Scripting.FileSystemObject
Set objFld = objFSO.GetFolder(FILE_PATH)

'Loop through each file in C:MyInvoiceFolder
For Each objFil In objFld.Files

If UCase$(Right$(objFil.Name, 3)) = FILE_EXT Then  'Only process PDFs

Application.StatusBar = "Printing Invoice file: " & objFil.Name

Shell """" & ADOBE_PATH & """/a /p /h """ & objFil.Path & """"

End If

Next objFil

'Clean up

Set objFil = Nothing
Set objFld = Nothing
Set objFSO = Nothing


Read Full Post »