Print Automatically Attachments

Not open for further replies.


New Member
Outlook version
Outlook 2013 64 bit
Email Account

I use Outlook 2013 64 bit standalone with Windows 10 Anniversary Edition.

Up to now, when I receive pdf invoices in a certain email account, I need to open the email and print them manually. There is the usual Rules settings into Outlook 2013 that will print all the pdf files attached to received emails. But this is not a solution in my case.

I have an email account that is exclusively used to receive invoices from purchases. The invoices are in pdf format. However, upon purchase some suppliers also send automatically pdf files with standard information about product returns, and other legalities concerning the purchase I just did. Some have 10 pages or so. For this reason, if I set to print automatically all pdf attachments from emails received in this specific email account, it will result in a huge waste of paper, ink, not to say the time to sort out manually the invoices from the other printed pdf email attachments. Therefore, it defeats the purpose of streamlining the invoice printing process.

I thought about selecting the emails through their Subjects. In my case, we receive from suppliers in three countries in Europe. So the email Subjects can come as Invoice or Facture or Rechnung according to the language. I do not know if there is a way to do this email selection by email Subject.

Other idea is to limit the printing only to one page. Invoices in my case are always one page pdf. In this way, when I receive the other pdf documents (not invoices), even if they have manhy pages, Outlook would print only the first page. This will limit manual work to select the printed invoices from the other useless documents.

Well, this is the problem I am facing. Any advice is welcome! :)
Here's a sample for printing automatically:
Print Attachments Automatically - VBOffice

In the ItemAdd event replace the PrintAttachments line by:
if instr(Item.Subject,"Rechnung")>0 or instr(Item.Subject,"Invoice")>0 then
PrintAttachments Item
(Extend the If statement to suit your needs.) Also, add ".pdf" to the case statement at the bottom.
Hi Michael, thank you for pointing out the VBA routine.

I did the modifications, but I am a newbie and still stuck with the points below:

1. The macro is marked in red at its first line, from Private Declare Functions until PrivatewithEvents line. This means I did something wrong or there is a bug in the macro.
2. I would need this macro to work only with one email account, not all email accounts in my Outlook 2013

I paste here the whole macro after my modifications. The macro instructions in italic are in red for me here on my side.

Any advice is welcome! :)


Sub PrintAttachmentsPDF()
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

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder

Set Ns = Application.GetNamespace("MAPI")
Set Folder = Ns.GetDefaultFolder(olFolderInbox)
Set Items = Folder.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
If InStr(Item.Subject, "Rechnung") > 0 Or InStr(Item.Subject, "Invoice") > 0 Or InStr(Item.Subject, "Facture") > 0 Then
PrintAttachments Item
End If
End If
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 = "C:\Users\xxxx\Desktop\xxx\Printed Email Invoices"

Set colAtts = oMail.Attachments

If colAtts.Count Then
For Each oAtt In colAtts

sFileType = LCase$(Right$(oAtt.FileName, 4))

Select Case sFileType
Case ".pdf"
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
End If
End Sub
End Sub
simply copy&paste the code as it is, and do only the mentioned modifications.
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
C automatically print attachments Using Outlook 4
5 Automatically print email attachments Using Outlook 7
J Automatically Print PDF When They Are Received Using Outlook 4
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
U Outlook not responding when trying to print Emails Using Outlook 6
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
S Cannot print Contacts Using Outlook 7
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M Batch print without appended trail of repeated e Using Outlook 2
Witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
M Custom Calendar Print Suggestions? Using Outlook 0
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
A Day view - print appointment details Using Outlook 1
I print calendar without subject and details Using Outlook 1
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
Diane Poremsky Print a list of your Outlook folders Using Outlook 0
Diane Poremsky Combine and Print Multiple Outlook Calendars Using Outlook 0
B Print list of previously sent recipients Using Outlook 1
R Print email message and attachment in order Outlook VBA and Custom Forms 2
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
A Print first page of a new email Outlook VBA and Custom Forms 7
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
S Macro to print & move selected emails? Using Outlook 3
J Auto print PDF attachments as they arrive with certain words in subject Outlook VBA and Custom Forms 3
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
D Outlook 2013 Categories won't print In color Using Outlook 2
G Calendar monthly view - Print just 3 weeks Using Outlook 5
R Can't modify Outlook view font with IE anymore (even though IE still affects print font) Using Outlook 5
M Print Attachments from another mailbox (not default) Outlook VBA and Custom Forms 2
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
L Outlook 2010 Quick Print Attachment, nothing happend Using Outlook 0
M button to send and print emails Using Outlook 26
S How to print ONLY first line of appointments in month view? Using Outlook 1
M print free/busy schedule of an user Using Outlook 2
O For Outlook 2007 - VBA to print attachments Using Outlook 1
W Cannot print Outlook 2007 emails Using Outlook 2
R problem with incomming e-mail I am unable to print full e-mail letter Using Outlook 1
M Custom print contacts Using Outlook 2
E Can't print from Outlook on wifi network Using Outlook 0
E can't print some retail discount coupons Using Outlook 7
J calendar print setup in outlook 2010 Using Outlook 1
J Outlook 2010 using Quick Print to print attachments Using Outlook 1

Similar threads