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 protected]”. 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 to 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!