Solved

Printing attachments with their respective messages in Outlook

Posted on 2011-03-05
1
348 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now