Debugging other people's code is a pain, so perhaps it would be simpler to just post a version that should work. This one goes in an ordinary module and not ThisOutlookSession (remove the earlier version from that folder). It uses a couple of standard functions from my web site to create the temporary folder (if not already present). The code includes a test macro so that you can test whether it works for you without the need to use the rule. Select a message and run the test macro.
Option Explicit
Private Declare Function ShellExecute 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
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
LSPrint olMsg
lbl_Exit:
Exit Sub
End Sub
Sub LSPrint(Item As Outlook.MailItem)
On Error GoTo Err_Handler
Dim oAtt As Attachment
Dim FSO As Object
Dim sTempFolder As Object
Dim cTmpFld As String
Dim strFilename As String
Dim strFullFile As String
Set FSO = CreateObject("scripting.filesystemobject")
Set sTempFolder = FSO.GetSpecialFolder(2)
'creates a special temp folder
cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
CreateFolders cTmpFld
'save & print
For Each oAtt In Item.Attachments
If Not oAtt.FileName Like "image*.*" Then 'Omit images in the message
strFilename = oAtt.FileName
strFullFile = cTmpFld & "\" & strFilename
'save attachment
oAtt.SaveAsFile strFullFile
'print attachment
ShellExecute 0, "print", strFullFile, vbNullString, vbNullString, 0
End If
Next oAtt
'Cleanup
If Not FSO Is Nothing Then Set FSO = Nothing
lbl_Exit:
Exit Sub
Err_Handler:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
End If
GoTo lbl_Exit
End Sub
Private Function FolderExists(fldr) As Boolean
'An Outlook macro by Graham Mayor
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
If (FSO.FolderExists(fldr)) Then
FolderExists = True
Else
FolderExists = False
End If
lbl_Exit:
Exit Function
End Function
Private Function CreateFolders(strPath As String)
'An Outlook macro by Graham Mayor
Dim strTempPath As String
Dim lngPath As Long
Dim vPath As Variant
vPath = Split(strPath, "\")
strPath = vPath(0) & "\"
For lngPath = 1 To UBound(vPath)
strPath = strPath & vPath(lngPath) & "\"
If Not FolderExists(strPath) Then MkDir strPath
Next lngPath
lbl_Exit:
Exit Function
End Function