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
Public
Sub
PrintSelectedAttachments()
Dim
Exp
As
Outlook.Explorer
Dim
Sel
As
Outlook.Selection
Dim
obj as
Object
Set
Exp = Application.ActiveExplorer
Set
Sel = Exp.Selection
For
Each
obj in Sel
If
TypeOf
obj is Outlook.MailItem
Then
PrintAttachments obj
EndIf
Next
End
Sub
Private
Sub
PrintAttachments(oMail
As
Outlook.MailItem)
On
Error
Resume
Next
Dim
colAtts
As
Outlook.Attachments
Dim
oAtt
As
Outlook.Attachment
Dim
sFile
As
String
Dim
sDirectory
As
String
Dim
sFileType
As
String
sDirectory =
"D:\Attachments"
Set
colAtts = oMail.Attachments
If
colAtts.Count
Then
For
Each
oAtt
In
colAtts
sFileType = LCase$(right$(oAtt.FileName, 4))
Select
Case
sFileType
Case
".xls"
,
".doc"
,
".pdf"
sFile = ATTACHMENT_DIRECTORY & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0,
"print"
, sFile, vbNullString, vbNullString, 0
End
Select
Next
End
If
End
Sub