View Full Version : Easy Printing from iPad with no 3rd Party Software (Outlook users only)

Phil A.
Oct 1, 2010, 05:34 AM
I know that 4.2 will bring AirPrint with it, but I'm not sure how long it will be before my Kodak Printer is supported, and I'm impatient anyway, so I thought I'd have a go at setting up printing from my shiny new iPad. This method uses functionality within Outlook (not Outlook Express), so I'm afraid it's for Windows users only (although it may be translatable to the new Mac Office Outlook if it supports the VBA object model). It is based on some code I found here (http://www.vboffice.net/sample.html?mnu=2&smp=3&cmd=showitem) (German site) with a few minor tweaks

What you need to do first of all is alter the trust centre settings of your outlook to allow unsigned macros to run (this may be a security concern for some people - if it is then get yourself a code signing certificate or else set the level to warn and allow it each time outlook starts).

Then, open up VBA by pressing Alt-F11, expand Project1, Microsoft Outlook Objects and double click on ThisOutlookSession.

Now, paste the following code into the code window:

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
Dim mail As Outlook.MailItem
Set mail = Item
If InStr(LCase(mail.Subject), "print me") <> 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:\Attachments\"

Set colAtts = oMail.Attachments

If colAtts.Count Then
For Each oAtt In colAtts

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

Select Case sFileType
Case "xlsx", "docx", ".pdf", ".doc", ".xls", ".ppt", "pptx", ".txt"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
End If
End Sub

Finally, close the VBA window and restart Outlook. You will need to create a folder called C:\attachments (or else rename the folder in the code). If you change the folder, make sure you include the trailing \ at the end of the path

What happens now is that whenever a mail arrives in your inbox with "Print Me" in the subject line, all attachments will be saved to the attachments folder and then printed out on your default printer (you can change the attachment types that are printed by changing the code line that starts Case "xlsx". Note that you will have to have applications installed on your machine that support the file types you are trying to print.
You can also change the trigger phrase within the code (make sure you use lower case in the code as it changes the case of the subject before doing a compare)

Now, from your iPad all you have to do is mail a document to yourself with "Print Me" in the subject line and it will be printed out (as long as outlook is running on your PC): This can be done from within most apps such as Pages, Docs to Go, etc.

The code as it stands will only work against the default inbox (i.e. not IMAP folders), but I'm sure it could be modified to work on IMAP accounts.

This can be tailored in a number of ways (for example, I had a spare machine so I've setup a separate exchange account for printing and execute without the subject line check so that it keeps printed mail away from my main mail and also means I don't have to worry about setting the subject line. I've also setup a scheduled job to periodically clear out the attachments folder), but hopefully it will prove useful for someone else out there!