Outlook macro to print cover email as well as the attachments:

Posted on 2009-02-23
Last Modified: 2013-12-17
I have a macro that works great with the exception that it doesn't print the cover page of the emails along with the attachments. Need some help getting the email to print with the attachments as well.


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 PrintAttachment()

Dim myItems, myItem, myAttachments, myAttachment As Object

Dim myOrt As String

Dim myOlApp As New Outlook.Application

Dim myOlExp As Outlook.Explorer

Dim myOlSel As Outlook.Selection

Dim strFile As String

'Set destination folder

myOrt = "C:\Program Files\Microsoft Office\"

On Error Resume Next

Set myOlExp = myOlApp.ActiveExplorer

Set myOlSel = myOlExp.Selection

For Each myItem In myOlSel

Set myAttachments = myItem.Attachments

If myAttachments.Count > 0 Then

For i = 1 To myAttachments.Count

myAttachments(i).SaveAsFile myOrt & myAttachments(i).DisplayName

strFile = myOrt & myAttachments(i).DisplayName

ShellExecute 0&, "print", strFile, 0&, 0&, 0&

Next i


End If


Set myItems = Nothing

Set myItem = Nothing

Set myAttachments = Nothing

Set myAttachment = Nothing

Set myOlApp = Nothing

Set myOlExp = Nothing

Set myOlSel = Nothing

End Sub

Open in new window

Question by:pover
    LVL 76

    Accepted Solution

    Hi, pover.

    Add this line


    somewhere after line #22 and before #25.

    Author Closing Comment

    thank you, that did the trick.
    LVL 76

    Expert Comment

    by:David Lee
    You're welcome.  Glad I could help.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
    Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
    This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    755 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

    18 Experts available now in Live!

    Get 1:1 Help Now