VBA‎ > ‎

VBA to print any file

We used this code to open a PDF document and print it.    But it should work with any file type as the code should know the program associated with file and print it correctly.
'First part of code
Public Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal Hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
'2nd part of code:
Public Sub Print(strFile As String)
    Dim hwndret As Long
    hwndret = apiShellExecute(0, "print", strFile, vbNullString, vbNullString, 3)

End Sub