How to Auto Print the Attachments in Incoming Task Requests via Outlook VBA

If your boss frequently sends various task requests which contain many task related attachments, you must hope that Outlook can automatically print out the attached files. This article will teach you how to use VBA to achieve it.

As we all know, not only can Outlook support us to send emails, but also it allows us to send meeting requests and task requests. Therefore, if you’re using Outlook for work, you must often receive a variety of meeting requests and task requests from your superior. In general, the task requests will always come packed with a lot of attachments, which are usually related materials. Then you will definitely print out these attached files. Under this circumstance, it will be better if Outlook can automatically print them. In response to this, here we will teach you a quick way which uses VBA to help you realize it without breaking a sweat.

Auto Print the Attachments in Incoming Task Requests via Outlook VBA

Auto Print the Attachments in Incoming Task Requests

  1. In the first place, start your Outlook application.
  2. Then press “Alt + F11” key buttons to access Outlook VBA editor.
  3. Next open the “ThisOutlookSession” project window.
  4. Subsequently, copy and paste the following VBA codes into this project.
Public WithEvents objItems As Outlook.Items

Private Sub Application_Startup()
    Set objItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub objItems_ItemAdd(ByVal Item As Object)
    Dim objTaskRequest As Outlook.TaskRequestItem
    Dim objTask As Outlook.TaskItem
    Dim objAttachments As Outlook.attachments
    Dim objAttachment As Outlook.Attachment
    Dim strMsg As String
    Dim nResponse As Integer
    Dim objFileSystem As Object
    Dim strTempFolder As String
    Dim objShell As Object
    Dim objTempFolder As Object
    Dim objTempFolderItem As Object
    Dim strFilePath As String
    On Error Resume Next
    If TypeOf Item Is TaskRequestItem Then
       Set objTaskRequest = Item
       Set objTask = objTaskRequest.GetAssociatedTask(True)
       Set objAttachments = objTask.attachments
    End If
    If objAttachments.Count > 0 Then
       strMsg = "Do you want to print the attachments in the new task request?"
       nResponse = MsgBox(strMsg, vbExclamation + vbYesNo, "New Task Request")
       If nResponse = vbYes Then
          Set objFileSystem = CreateObject("Scripting.FileSystemObject")
          strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\TEMP" & Format(Now, "hh-ss-dd-mm-yyyy")
          'Create a new temp folder
          MkDir (strTempFolder)
          For Each objAttachment In objAttachments
              'Save all the attachments to the newly created folder
              strFilePath = strTempFolder & "\" & objAttachment.FileName
              objAttachment.SaveAsFile (strFilePath)
              'Print all the items in the newly create folder
              Set objShell = CreateObject("Shell.Application")
              Set objTempFolder = objShell.NameSpace(0)
              Set objTempFolderItem = objTempFolder.ParseName(strFilePath)
              objTempFolderItem.InvokeVerbEx ("print")
          Next objAttachment
       End If
    End If
End Sub

VBA Code - Auto Print the Attachments in Incoming Task Requests

  1. After that, sign this code.
  2. Later change Outlook macro settings to permit the digitally signed macros.
  3. Finally, you can restart your Outlook to activate the new VBA project.
  4. From now on, every time any new task request arrive in your inbox, you will get a message asking if to print the task attachments, like the following image:Ask if to print the attachments
  5. If you select “Yes”, all the attachments will be printed out automatically.

Exempt from Frequent PST Troubles

If you’re used Outlook for decades, you will surely meet up with many PST issues. In this case, you have to back up your PST file as soon as possible. Then recur to the inbox repair tool to try to solve the problems. Assuming that it fails, you can continue to resort to a more remarkable tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server recovery and outlook repair software products. For more information visit

Comments are closed.