Solved

Printing attachments with their respective messages in Outlook

Posted on 2011-03-05
1
379 Views
Last Modified: 2012-05-11
The macro posted with: http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_22933400.html?sfQueryTermInfo=1+10+30+attach+email+macro+outlook+print

does not print pdf attachments. In case of one email with 3 .jpg attachments, it printed one of them twice and skipped another.  I would appreciate fixes to these.  Is it possible to add a pause option after printing each email or attachment, and ask for an input to continue?

Thank you.
0
Comment
Question by:fl160
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 35049294
Hi, fl160.

Try this version.  This uses a different method to print Acrobat files and pauses after each item.
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


Sub PrintMessageAndAttachments()
    Dim olkMsg As Outlook.MailItem, _
        olkAtt As Outlook.Attachment, _
        objShell As Object, _
        strFilename As String, _
        strCommandLine As String
    
    Set objShell = CreateObject("WScript.Shell")
    
    For Each olkMsg In Application.ActiveExplorer.Selection
        '--- Print the message ---'
        olkMsg.PrintOut
        '--- Print the attachments ---'
        For Each olkAtt In olkMsg.Attachments
            strFilename = Environ("Temp") & "\" & olkAtt.FileName
            olkAtt.SaveAsFile strFilename
            Select Case LCase(Right(olkAtt.FileName, 3))
                Case "pdf"
                    'Change the printer name on the next line'
                    strCmdLine = "AcroRd32.exe /t """ & strFilename & """ ""HP Deskjet 3320"""
                    objShell.Run strCmdLine, 0, False
                Case Else
                    ShellExecute 0&, "print", strFilename, 0&, 0&, 0&
            End Select
        Next
        If msgbox("Do you want to continue printing items?", vbQuestion + vbYesNo, "Print Message and Attachments") = vbNo Then
            Exit For
        End If
    Next
    
    'Cleanup'
    Set objShell = Nothing
    Set olkAtt = Nothing
    Set olkMsg = Nothing
End Sub

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question