Printing Attachments

  • Thread starter Thread starter Jim Pockmire
  • Start date Start date
J

Jim Pockmire

Is there a way to automate the printing of an attachment to an email
message, without first opening up the message and then printing the
attachment (either through an add in or VBA)?

(e.g. our company sends out 1,500 advertising orders each month, and there
is a confirmation of order attached to a return email for each order - that
needs to be printed.)
 
Hi Jim,

it´s easiliy possible with VBA as long as you´ve an application
registered for the attached file.

You can use the Inbox item´s ItemAdd event for handling the incoming
mails. Then loop through the MailItem.Attachment collection with For
Each and store each attachment into your file system with
Attachment.SaveAsFile. From the file system you can print known files
with the ShellExecute.

Sample for ShellExecute:

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

Const SW_HIDE = 0

Public Function PrintFile(sFile As String, _
Optional lHwnd As Long _
) As Boolean
On Error Resume Next
PrintFile = CBool(ShellExecute(lHwnd, "print", sFile, vbNullString,
vbNullString, SW_HIDE))
End Function
 
Back
Top