How-To Geek
Batch Print PDF Attachments in Outlook
This article was written by Sean Tsai, a data warehousing expert and good friend of the How-To Geek
Have you ever wanted to print every attachment you receive in your Outlook email box? Let’s say you subscribed to a free fax to PDF email service and you want them to be printed out automatically just like an old fashioned fax machine.
Here is a quick way to achieve that if you are comfortable with a little bit of VB (macro) programming.
What we showing here is to create a rule in Outlook and move the incoming fax emails into a separate subfolder. Using VB code we create a macro for you to run a print job against every email in that subfolder so you don’t have to open up the email and print the attachments one by one.
Step 1
Create a subfolder named “Batch Prints? under “Mailbox – YourName? in Outlook.
Step 2
Create a rule (from menu Tools/Rules and Alerts) in Outlook that looks like this:
Place the email address from your fax vendor in the field “email@myfaxservice.com.? In the subject line, place the persistent text that is sent from the fax vendor every time (don’t put in the text that will be altered periodically). The 3rd field “Batch Prints? is the subfolder you just created in the first step.
Step 3
Create a VB macro. First bring up the VB editor by going to Tools/Macro/Visual Basic Editor. You should see the VB editor looks like this:

Step 4
From the left side Project window, right click on the Project1 item and insert a module named “Module1?:

Step 5
Once the Module1 is created, copy the code below into the window on the right side as shown in the bullet #3.
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("Batch Prints")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
‘ all attachments are first saved in the temp folder C:\Temp. Be sure to create this folder.
FileName = "C:\Temp\" & Atmt.FileName
Atmt.SaveAsFile FileName
‘ please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
Shell """C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe"" /h /p """ + FileName + """", vbHide
Next
Item.Delete ‘remove this line if you don’t want the email be deleted automatically
Next
Set Inbox = Nothing
End Sub
Note that you might need to change the line of code that calls Acrobat to match the path on your system.
Step 6
Now the setup is complete. All the emails from your fax vendor will be moved to your “Batch Prints? when they come in. Please note, in the example, we are expecting all attachments are in PDF format so we use Acrobat acrord32.exe to print every attachment.
Using the Macro
Now, when you want to print all attachments, simply go to the macro and run the macro PrintAttachments and all attachments will be printed sequentially. Email will be deleted and moved into trash bin once it has printed.
Note: the prints are routed to your default printer so you have to make sure a valid printer driver is setup and selected.

Hope this is useful!
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (75)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 12/11/07




I need to be able to print to a pdf/convert to a pdf emails WITH their attachments showing underneath the body of the email. I know how to convert the email and attachments seperately but I need them to be in one document. Is there a plug-in or anything to do this?
Can I do this if Fax to PDF emails come in online shared mailboxes (the ones that you can add in Exchange Sever settings under Advanced tab, “Open these additional mailboxes”)? We have Inbox in an additional mailbox where all of our Faxes come in and I would like the script to print those attachments and then move the files to the “Completed” folder. I would greatly appreciate if you could help me out with this.
Nino
Nino,
Yes, you should be able to print any folder you want. The trick is to set the folder statement:
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Prints”)
to whatever the folder you want to print. Use the “Parent? method to find your folder in the hierarchy.
To move the email to other folder, simply use the method “Move? as follow:
‘Item.Move GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Another Folder”)
As you can see the pattern here, GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox) can get you to the default inbox folder. Using “Parent? or “Folder? method will allow you to traverse through the folder hierarchy.
Question,
The statement Item.Delete, I want to delete after the user confirms all attachments printed OK. I made this little routine using your doe. but it’s leaving one item in “Batch Print” folder in Outlook. Why is it not deleting all the items inthe folder?
Here’s my code.
Private Sub cmdYes_Click()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Print”)
For Each Item In Inbox.Items
Item.Delete
Next
Set Inbox = Nothing
Kill “c:\Batch Print\*.*”
Unload frmConfirmDelete
End Sub
It sounds like a timing issue. The print job might still be taking place while you are trying to delete the items.
Sean,
Very good article.We have a similar requirement.
We have a outlook VBA which checks the incoming mails and if it matches with particular sendername & subject name it process the mail and automatically generating a document.
In our outlook we have two mailboxes one is Personal mailbox and another one is shared mailbox.
Application_NewMail fired whenever mail comes to “Personal Mailbox” .Actually we need to process the “Shared Mailbox” whenever new mail comes into it.
Is it possible? I tried via Outlook Startup & Quit it works fine. But we want to automate this one, like whenever a mail comes into shared mailbox the macro code should be executed.
Can anybody help me?
–Anand
Thanks, Geek. Your solution worked perfectly for me, but only after I had replaced all the missing backslashes from the file paths after copying and pasting your code. Fortunately you have a screenshot above so I could spotted the problem quickly.
Anand,
You can achieve that simply with rules by running a script (macro) as soon as the item is identified. Here is the code snippet.
Sub AutoPrintAttachments(Item As Outlook.MailItem)
‘ this loop goes through all attachments and print them all
For Each Atmt In Item.Attachments
FileName = “C:\Temp\” & Atmt.FileName
Atmt.SaveAsFile FileName
Shell “”"C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe”" /h /p “”" + FileName + “”"”, vbHide
Next
‘ Uncomment the line below if you want to delete the email after print
‘ Item.Delete
‘ Uncomment the line below If you like to save the email in another folder (move the email)
‘ Remember to change the folder name “Another Folder? to the name of your destination folder
‘Item.Move GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Another Folder”)
End Sub
It is very similar to batch print but the function declaration (Sub AutoPrintAttachments(Item As Outlook.MailItem)) is a bit different. Outlook will pass down the email that satisfiies your rule to this subroutine and you can process the item by accessing the “Item” object.
Hope this helps.
So does “AutoPrintAttachments” require the same dim statements as the original macro?
And this long name “AutoPrintAttachments(Item As Outlook.MailItem)” seems to confuse the VB editor.
Could you repost the second macro in its entirety, with all necessary code?
Thanks.
Also, when I run the original macro from the macro menu, I get a VB error: “sub or function not defined.” However, if I press the little triangle button in the VB editor for “Run Sub/User Form,” the macro works fine…
OK, last but not least, no matter which printer I print to (there are a variety around), none of them knows the paper type that Acrobat seems to be sending them, which is variously reported as “Monarch” or “Free Plain” depending on the printer.
I’ve receiving the error ‘Cannot save the attachment. Path does not exist. Make sure the path is correct’
I have created the c:\Temp directory, so I’m not sure what is up.
Sean,
This seems to be exactly what I need but I have one question- does this macro need to be run manually. I’d like to schedule it to run every few minutes or print the faxes (email attachments) as they are received or moved into the “Batch Prints” folder.
Is there a way to automate this? Thanks!
Sean,
Also, one other question. How should I modify the following statement to accomodate the fact my email is stored in a .PST file. In other words, my mail is stored in a PST (Personal Folder). For example, my Inbox is nestled as follows: “Personal Folders” –> “Inbox” –> “Batch Prints” :
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Print”)
Thanks again.
Michael
I am recieving the same ‘Cannot save the attachment. Path does not exist. Make sure the path is correct’ message as Michael. I also created the c:temp directory and cannot figure out where I am going wrong. Please help…
Very helpful article.
I am having an issue with the GetNameSpace statement.
it looks like the method needs and expression in front (see http://msdn2.microsoft.com/en-us/library/aa220108(office.11).aspx):
expression.GetNameSpace(Type)
expression Required. An expression that returns an Application object.
Type Required String. The type of name space to return.
how do i make this work?
I have learned a lot from this article and the FUP comments — I am not a programmer but I need to find a way to batch print PDFs. I set up the rule in Outlook without issue, following the sample above. However, I am still having trouble getting the macro to run. The first error that I was getting was “Compile error: For without Next” and so I added back in the line for Next Item.Delete (don’t know if this will fix it, though). Tthe next error is “Run-time error ’2147221233 (8004010f)’: The operation failed. An object could not be found.” I click debug and the debugger is now highlighting the Set Inbox= line. NOTE: My inbox is is my Personal Folder… my code so far is:
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Prints”)
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = “C:\Temp\” & Atmt.FileName
Atmt.SaveAsFile FileName
Shell “”"C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe”" /h /p “”" + FileName + “”"”, vbHide
Next
Item.Delete
Next
Set Inbox = Nothing
End Sub
I have tried the codes and it work wonderfully for pdf attachments. I would also like to print files with html attachments and would like to have the codes. Please help.
THANK YOU!!!
I just pasted the line with shell on it into my current code to save attachments- and under the pdf if statement- worked PEERRFECTLY!
just make sure that you are happy with your default printer- bcoz it auto prints there.
HELP! This is exactly what I need. And it worked GREAT on my Outlook 2003 standalone on my laptop. However, it doesn’t work on my office pc (where I need it to work) running Outlook 2003 connected to an Exchange server. At the “For Each Item In Inbox.Items” line, I get a “Run-time error ’13′ Type mismatch” error.
Any thoughts?
Nevermind. Got it! I commented out the “Dim Item As MailItem” line. It seems it does not need that variable in the For Each statement.
Thanks for the code! Saved me lot’s of manual time!
-t
Hi, how would you modify this macro to automatically print any attachment (.pdf, work, excel..) without the email?
Hi Sean,
Thanks a lot for all your help. This saves me an hour or more a day.
However I face a problem that wastes a lot of paper that I was wondering if you could solve:
The documents that I need to print are either 2 or 4 pages. I only need pages 1 and 3.
Any code I could add to only get the odd pages to print?
Hi,
this program is working fine for attachment mails but could you please provide me vb code for printing mail which does have attachment……
Hi – nice piece of code, however when I used the Item.move command, 1 email was always left in the original folder, I used this loop to remove the last one, any ideas why? (Using Outlook 2007, windows XP)
Dim Printed As MAPIFolder
Set Printed = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Folders.Item(“Printed”)
myloop:
For Each Item In Inbox.Items
Item.Move Printed
Next
If Inbox.Items.Count > 0 Then GoTo myloop
Hello,
Can someone tell me how i can print TIF file using “Microsoft Office Document Imaging”?
thanx
Sean,
I set everything up and I am getting a runtime error. “…an object could not be found.” I am assuming this is because I am running outlook on our exchange server? The debug points to the Set Inbox line. Any ideas? Thank you
Sean,
I am using Office 07 and when I tried your code I kept on getting an error with this statement:
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Prints”)
Do you know if I have to make any changes for the 07 version?
Thanks,
Works well except the format of file path is not correct. thanks
How to access my office id through g-mail or yahoo mail
I am having the same problems as Shane and Kevin. Any word on how to fix this? Thank you!
Sean,
your macro works great, thanks.
Please be so kind and suggest a way to run the macro automatically from a rule.
I am using Outlook 2007 and would like to select,, with a rule, first all faxes (pdf files) arriving from a fax service, move them into a fax folder and then run a script (your macro) to print automatically.
Thank you
When i have copy paste the script into VB I get an Run-Time error’- 2147221233 (8004010f)’:
Any one can help ?
Best regard
Henrik
i need to print mailbox name on each attachment in outlook 2003
Hi,
Is there a way to specify a printer other than the default?
I cant get this thing to work. I get ‘The next error is “Run-time error ‘2147221233 (8004010f)’: The operation failed. An object could not be found.” I click debug and the debugger is now highlighting the Set Inbox= line.
Does anyone have the answer to why this is happening and to work make it work.
This could save me alot of time hassle
I am using Office 07 and when I tried your code I kept on getting an error with this statement:
Set Inbox = GetNamespace(”MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(”Batch Prints”)
Hi
I’ve several pdf files with the same name, so I got an error that says the attachment can not be saved. (runtimeerror 1075380192 (bfe70020) Is there a way to generate a automatic filename?
Thanks for your help!
Key step to make this work (w/Outlook ’07/Exchange): Create “Batch Prints” folder in the top directory, not in the Inbox folder.
When I first installed this code into a module in seemed to work fine, but for some unknown reason, it is now only printing and deleting 1 email and attachemnt and not moving on to the rest. Any ideas what might be happening? I notice if I remark the item.delete and do not delete the emails after printing, it will print all the attachments. The problem is they do need to be deleted so they do not get printed again later.
Thanks
I use this in Outlook 07 and it works great for 1 or 2 emails. But it gets goofy with anymore than 3 emails. It will sometimes print one attachment twice and skip some attachments and not delete them. I still have to go into my Batch Prints folder, right click the attachments it didn’t print, print it and then I have to manually delete it. I think it needs a pause somewhere. I am using the code as it is on this page- with my file path for Adobe Reader. Can anyone tell me where to place a pause? I am a noob to VB and don’t know the language to make it work. Any help is appreciated.
I finally worked this code out today, brilliant. It kept giving me syntax errors and I realise I am suppose to remove the helpful comments starting with the apostrophe! Am new to this as you can see. Now it works and I am slightly wiser, thanks.
My question is – can I get it to print only page one of the PDF by adding a command to the shell line?
I am using Office 2007 and when I tried your code I kept on getting an error with this statement:
Set Inbox = GetNamespace(”MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(”Batch Prints”)
Please help me fix this, it would save me so much time at work.
Thanks,
Dan
I got it to work in Office 2007 which i am superbly happy about.
The probelm that was stopping me was that I needed to put the Batch Prints Folder into my
Mailbox- Daniel
not into my Inbox.
I hope it works for you!!!
I tried this but I can only get it to save the first file onto the pdf document. Is there a way to make it save all the documents into one pdf. Here is a copy of the code I am using:
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Prints”)
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = “C:\Temp\” & Atmt.FileName
Atmt.SaveAsFile FileName
Shell “”"C:\Program Files\Adobe\Reader 9\Reader\acrord32.exe”" /h /p “”" + FileName + “”"”, vbHide
Next
Set Inbox = Nothing
Next
End Sub
Should the script auto run?? I can only make it print if I manually run the macro?!?
hey there – thanks for much for putting this together. I do have one slight problem… When i try to run the macro i get the following error:
run time error -2147221233 (8004010f) operation failed an an object could not be found
any help?
Ok, here’s a problem I’m seeing. If I have 2 emails with the same attachment name, the 1st email prints twice even though the contents of each attachment are different. I think it has to do with the 1st file in C:\temp not being overwritten/deleted. Is there a way to have the macro delete the file from C:\temp after it is finished printing it (before the next email/file is printed)?
And thanks for putting this together. It’s really a great tool.
Thanks so much for putting this together. I’m having one small problem however some attachments print twice and other get missed altogether. Is there a pause I need to put into place?
Any help would be appreciated.
Thanks again
Thank you Adam and Daniel for fixing my issue, and thank you Sean for the wonderful code!
I have fixed a few problems I had with the original script below. Note I had the issue of the same name or same filename. Also I am not using Adobe Acrobat instead I am using FoxIt Reader. So you will see my code below is adjusted for that. You can get the parameters for FoxIT reader by issuing a /? as a command line argument.
I added the “Dim Filenameincrementer As Integer” and “Filenameincrementer = 1″ lines to the header of the script then added “& Filenameincrementer” to the filename section. Then finally increment the integer by one with “Filenameincrementer = Filenameincrementer + 1″ (I know there is another way and quicker way to do this but I needed this script to work quickly and just made it work. Someone here will clean it up.)
I also wanted the emails to be marked as read and moved to a folder so I adjusted those lines as well. See my code below. I hope this helps those that needed it. Thank you for providing the inspiration code and a working model for me to begin with!
CODE:
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim Filenameincrementer As Integer
Filenameincrementer = 1
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“@_TO PRINT”)
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
‘ all attachments are first saved in the temp folder C:\Temp. Be sure to create this folder.
FileName = “C:\Temp\” & Atmt.FileName & Filenameincrementer
Atmt.SaveAsFile FileName
‘ please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
Shell “”"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe”" -p “”" + FileName + “”"”, vbHide
Filenameincrementer = Filenameincrementer + 1
Next
‘ Uncomment the line below if you want to delete the email after print
‘ Item.Delete
‘ Uncomment the line below If you like to mark the mail item as read
‘ Item.UnRead = False
‘ Uncomment the line below If you like to save the email in another folder (move the email)
‘ Remember to change the folder name “Another Folder?? to the name of your destination folder
‘ Item.Move GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Another Folder”)
Next
Set Inbox = Nothing
End Sub
:END CODE
Mr. Thirteen
I am using a similar code as above.
Although the macro has been created in VB and can be run as a macro, when creating the rule to run the script it shows no scripts available. What am I doing wrong?
Denis
Thanks!!! This is exactly what I need.
But is it also possible to automatically print duplex, so I can save paper?
Donald
How can I alter script to print excel attachments?
thanks
Hi All
Good ide with this vb …
But in 2007 , you can make this as a rule — and print all the attachments , in pdf.
You use you default printer , and if you setup the driver – to duplex , all will be in duplex .
With print from excel – ask users to save sheet as pdf and then mail them ….
Remember to set you printer to print attachments – this is done in the print dialog box in outlook 2007 , then you rule will work perfekt …
Hi there, i receive some emails with txt, csv and pdf attachments (in each email). I need to prin ONLY the pdf files. Can i do this with this macro?
Thank you
I have to run the macro every time i want to print. I didn’t make the rule because I want to choose which files to print and I figured the act of moving the message to my print folder could serve that purpose. Also, I have Outlook 2007, does that affect my ability to make a suitable rule? So, my real question is: does that rule cause the macro to run? Is that why I have to manually run the Macro? Thank you for the code and all the follow ups!
Is there a way to identify a specific user’s Inbox assuming two email accounts are open? Our Accounting folks have their personal and the AccountsPayable mailboxes (mailbox that receives invoices) open simultaneously in Outlook so to manage/see both. Looking for a way to reference the AccountsPayable mailbox’s “Inbox” and “Batch Prints” folders in both the Rule and Macro routines. Thank you!
My version for Tif fiels with Microsoft Document Image Viewer also only prints unread emails.
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim Filenameincrementer As Integer
Dim Result As Double
Filenameincrementer = 1
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Folders.Item(“TOPRINT”)
For Each Item In Inbox.Items
If Item.UnRead = True Then
For Each Atmt In Item.Attachments
FileName = “C:\Temp\” & Atmt.FileName & Filenameincrementer
Atmt.SaveAsFile (FileName)
Result = Shell(“”"C:\Program Files\Common Files\microsoft shared\MODI\12.0\MSPVIEW.EXE”" -p “”" & FileName & “”"”, vbHide)
Filenameincrementer = Filenameincrementer + 1
Next
End If
Item.UnRead = False
Next
Set Inbox = Nothing
End Sub
Great Script Sean
We have a number of different attachments e.g PDF’s TIFF’s and also HTML’s
Emails come into a single inbox and works fine for PDF’s.
Any ideas how to modify the script to print all 3 attachment types ?
Thanks
G
I am SOOOO glad I found this!!!! I’ve been messing with MAPILabs Print tools for Outlook and have had various problems with it working on some machines and not others. I was able to get this to work and my end users love it!!! Works on every pc I’ve configured.
awesome thanks, just had to delete the comments and modify the reader path
nice one, but I have a job to automate that requires first printing email content (1st page for paper saving) then email pdf attachment(s). the problem is that when using to different methods of printing the order of the printing items mixes :( here’s modified code used by me:
Set Inbox = GetNamespace(“MAPI”).PickFolder
For Each Item In Inbox.Items
Item.PrintOut ‘<—— mail content printing, unfortunately it can't be modified so I have to print all
For Each Atmt In Item.Attachments
mailsubj = Item.Subject
maildate = Item.ReceivedTime
FileName = "C:\Temp\" & Atmt.FileName
If Right(FileName, 4) = ".pdf" Then
Atmt.SaveAsFile FileName
Shell """C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe"" /h /p """ + FileName + """", vbHide
End If
Next
Next
Set Inbox = Nothing
when I run this code somehow I get first printed attachment and after that the email content. How to obtain the correct order?
This works great, but i ran into an issue where I have multilple email attachments with the same PDF file name. So the I am having a lot of trouble saving/printing all the file to the C:\Temp drive
Does anyone know of some type of batch command to add to this one above that can Auto-Rename the PDF’s as they are created?? Or a way around this problem?
@ cheers
insert
“Filenameincrementer = Filenameincrementer + 1″
after the address for the program location. each time it saves a document it adds a number at the end.
This post is old, and I’m sure everyone using the code has fixed it already, but I’m surprised nobody has mentioned this yet:
In VBA, the ‘+’ sign is for addition, not concatenation.
Also, as part of an expression, the parameters for the Shell function must be in parentheses. This code doesn’t even compile and should be fixed.
Shell “”"C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe”" /h /p “”" + FileName + “”"”, vbHide
The Outlook Rule Wizard for printing the email and printing all the attachments could work, but I only need to print pdf attachments, and usually the email will come with pdf and xls attached, so the Rule wont work for me.
And the script that is posted aboce is a good script, but has some errors. First, the attachments are not printed in order, so for example, if there are 3 emails, with 3 pdfs each, the macro will print the attachments with a weird order, not first 3 attachments from first email, then the next three attachments for the second email and then the next three attachments for the third email, so when you go to the printer, you dont have a mess, which is what happens with the above code.
Plus, the last code, with the incrementer does not work, it leaves you with a .pdf1 ; .pdf2 ; .pdf3 that the system will not open it. For last, I will need to print the emails also, so attachments, email, atachments, corresponding email and attachments and corresponding email, for whatever amount of emails are in the folder.
Hi Sean,
Can you please contact me. I would like to sub you to do a small project similar to this.
Thanks!
Thanks for the script and all the comments. These were very helpfull, although I wanted to print attachments using standard microsoft software and not any third party software. Therefore I changed the Shell command a bit, like this:
Shell “”"C:\Windows\system32\rundll32.exe”" C:\Windows\system32\shimgvw.dll,ImageView_PrintTo /pt “”" + FileName + “”" \\FILE01\PRT0003″”", vbHide
This uses standard software to open the file and print it to the printer I needed.
Eish Sean, thanks for the script (if u r still around). It works beautiful. Also thanks to the people who replied with the modifications on the code, it was awesome.
I have outlook 2007. I cant figure out how to get this to work. I am trying to auto print the pdf attachments from an online fax. Please help.
Thanks so much for this post. Great resource. I needed something to print attachments as an e-mail comes in from my fax-to-email provider, so I tweaked your code a bit, but the base code was extremely helpful. I created a rule to run this script (macro) when I receive an e-mail from my provider. Works like a charm. Again, Thanks.
Public Sub PrintAttachments(Item As Outlook.MailItem)
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
For Each Atmt In Item.Attachments
FileName = “C:\temp\” & Atmt.FileName
Atmt.SaveAsFile FileName
Shell “”"C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe”" /h /p “”" + FileName + “”"”, vbHide
Next
Set Inbox = Nothing
End Sub
The code is working fine for me, but the emails that I recieve have the company logo as an attachment in the signature of the Email. Thus this image001.png file is trying to open in Adobe Acrobat and Adobe gives me an error stating it can not open the *.png file in Adobe Acrobat. This error is causing some of the PDF’s attachments to not print. Is there a way to modify the code to specifically target the PDF files only?
Hi I tried to use this in my Outlook 2010 but it is not working
I have Adobe 9 reader
I change the path to C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe, but still giving me Syntax error.
Can you help me in this
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set Inbox = GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Parent.Folders.Item(“Batch Prints”)
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
‘ all attachments are first saved in the temp folder C:\Temp. Be sure to create this folder.
FileName = “C:\Temp\” & Atmt.FileName
Atmt.SaveAsFile FileName
‘ please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
Shell “”"C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe”" /h /p “”" + FileName + “”"”, vbHide
Next
Item.Delete ‘remove this line if you don’t want the email be deleted automatically
Next
Set Inbox = Nothing
End Sub
Is it possible to set som argument that will make it possible to print ONLY the first and last page of the PDF doc ?