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
Solved

Printing attachments with their respective messages in Outlook

Posted on 2011-03-05
1
372 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Outlook Free & Paid Tools
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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