none
Print attachments automatically from specific incoming email as soon as they arrive on Microsoft Office 2016 Outlook RRS feed

  • Question

  • Hi everyone,

    Can i print attachments automatically from specific incoming email as soon as they arrive on Microsoft Office 2016 Outlook? How can i create rule for that? do i still need VBA script for Microsoft Office 2016 Outlook like office outlook 2010?

    I mostly receive one attachment from specific email that i need to print? can anyone help  me VBA code if its require?

    After print if email can be moved to specific folder would be great.  

    Thank you

    Suresh

    Friday, April 8, 2016 9:00 AM

Answers

  • Hello Suresh,

    You can develop a VBA macro where you need to handle the NewMailEx event of the Application class.

    This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when theEntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.

    The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. 

    In the event handler you can access attachments by using a corresponding property of the MailItem class. The Attachment class doesn't provide any methods for printing. But as a workaround you may consider saving attached files on the disk and then print them by launching a command. The SaveAsFile method of the Attachment class saves the attachment to the specified path. For example:

    Sub LSPrint(Item As Outlook.MailItem)  
        On Error GoTo OError
          
        'detect Temp
        Dim oFS As FileSystemObject
        Dim sTempFolder As String
        Set oFS = New FileSystemObject
        'Temporary Folder Path
        sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)
        
        'creates a special temp folder
        cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
        MkDir (cTmpFld)
        
        'save & print
        Dim oAtt As Attachment
        For Each oAtt In Item.Attachments
          FileName = oAtt.FileName
          FullFile = cTmpFld & "\" & FileName
          
          'save attachment
          oAtt.SaveAsFile (FullFile)
          
          'prints attachment
          Set objShell = CreateObject("Shell.Application")
          Set objFolder = objShell.NameSpace(0)
          Set objFolderItem = objFolder.ParseName(FullFile)
          objFolderItem.InvokeVerbEx ("print")
    
        Next oAtt
        
        'Cleanup
        If Not oFS Is Nothing Then Set oFS = Nothing
        If Not objFolder Is Nothing Then Set objFolder = Nothing
        If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
        If Not objShell Is Nothing Then Set objShell = Nothing
        
      OError:
        If Err <> 0 Then
          MsgBox Err.Number & " - " & Err.Description
          Err.Clear
        End If
        Exit Sub
    
      End Sub

    See Automated Attachment Printing Outlook 2010 for more information. Also you may find the Macro to Print Outlook email attachments as they arrive page helpful.

    In case if you need to move the item to another folder you can use the Move method which moves a Microsoft Outlook item to a new folder.


    [custom.development]

    Monday, April 11, 2016 10:48 AM

All replies

  • Hi,

    In the current design of Outlook, there is no such feature.

    While with the help of VBA code, I think this request can be realized.

    I'll move this thread to the Outlook for Developers forum so that you can get assistance about VBA.

    Regards,

    Melon Chen
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.
    Monday, April 11, 2016 5:11 AM
  • Hello Suresh,

    You can develop a VBA macro where you need to handle the NewMailEx event of the Application class.

    This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when theEntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.

    The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. 

    In the event handler you can access attachments by using a corresponding property of the MailItem class. The Attachment class doesn't provide any methods for printing. But as a workaround you may consider saving attached files on the disk and then print them by launching a command. The SaveAsFile method of the Attachment class saves the attachment to the specified path. For example:

    Sub LSPrint(Item As Outlook.MailItem)  
        On Error GoTo OError
          
        'detect Temp
        Dim oFS As FileSystemObject
        Dim sTempFolder As String
        Set oFS = New FileSystemObject
        'Temporary Folder Path
        sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)
        
        'creates a special temp folder
        cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
        MkDir (cTmpFld)
        
        'save & print
        Dim oAtt As Attachment
        For Each oAtt In Item.Attachments
          FileName = oAtt.FileName
          FullFile = cTmpFld & "\" & FileName
          
          'save attachment
          oAtt.SaveAsFile (FullFile)
          
          'prints attachment
          Set objShell = CreateObject("Shell.Application")
          Set objFolder = objShell.NameSpace(0)
          Set objFolderItem = objFolder.ParseName(FullFile)
          objFolderItem.InvokeVerbEx ("print")
    
        Next oAtt
        
        'Cleanup
        If Not oFS Is Nothing Then Set oFS = Nothing
        If Not objFolder Is Nothing Then Set objFolder = Nothing
        If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
        If Not objShell Is Nothing Then Set objShell = Nothing
        
      OError:
        If Err <> 0 Then
          MsgBox Err.Number & " - " & Err.Description
          Err.Clear
        End If
        Exit Sub
    
      End Sub

    See Automated Attachment Printing Outlook 2010 for more information. Also you may find the Macro to Print Outlook email attachments as they arrive page helpful.

    In case if you need to move the item to another folder you can use the Move method which moves a Microsoft Outlook item to a new folder.


    [custom.development]

    Monday, April 11, 2016 10:48 AM