I have been tinkering with the code. I added a different image viewer as the print application. And I am trying to get other formats to print like pdf. Image prints perfectly. PDF won't print at all. Running over the script I don't think you limited printing to just image files. Any idea why PDF won't print?
'This is the module for the auto print function. It relies also on a part in the ThisOutlookSession.Option Explicit
Public Sub PrintAttachments(olItem As MailItem)
'Graham Mayor - http://www.gmayor.com - Last updated - 08 Mar 2018
Dim olAttach As Attachment
Dim strFname As String
Dim strExt As String
Dim j As Long
Dim strSaveFldr As String
strSaveFldr = Environ("TEMP") & "\"
On Error GoTo lbl_Exit
If olItem.Attachments.Count > 0 Then
For j = 1 To olItem.Attachments.Count
Set olAttach = olItem.Attachments(j)
If Not olAttach.FileName Like "image*.*" Then
strFname = olAttach.FileName
strExt = Right(strFname, Len(strFname) - InStrRev(strFname, Chr(46)))
Select Case LCase(strExt)
'Case Is = "tif", "jpg", "png", "gif"
' olAttach.SaveAsFile strSaveFldr & strFname
' 'Shell "cmd /c mspaint /p " & strSaveFldr & strFname
' Shell "cmd /c D:\work\PortableApps\PortableApps\IrfanViewPortable\App\IrfanView\i_view32.exe " & strSaveFldr & strFname & " /print"
'Case Else
'Changes start
Case Is = "tif", "jpg", "png", "gif"
olAttach.SaveAsFile strSaveFldr & strFname
Shell "D:\work\PortableApps\PortableApps\IrfanViewPortable\App\IrfanView\i_view32.exe " & strSaveFldr & strFname & " /print"
Case Is = "pdf"
olAttach.SaveAsFile strSaveFldr & strFname
Shell "D:\work\PDFtoPrinter\PDFtoPrinter.exe" & strSaveFldr & strFname
Case Else
'Changes end
End Select
End If
Next j
olItem.Save
End If
lbl_Exit:
Set olAttach = Nothing
Set olItem = Nothing
Exit Sub
End Sub
Edit: Nevermind. Being the idiot that I am, I forgot to leave a space after the executable.
Shell "D:\work\PDFtoPrinter\PDFtoPrinter.exe " & strSaveFldr & strFname
That fixed it. Great stuff.