Printing multiple e-mails with multiple attachments in consequitive order.

I need to be able to print out multiple e-mails (which have multiple attachments of various types) in consequitive order out of Outlook 2003.
i.e. (1) E-mail no.1 (2) attachment no.1(word) to e-mail no.1 (3) attachment no.2(excel) to e-mail no.1 (4) E-mail no.2 (5) attachment no.1(pdf) to e-mail no.3 (6) attachment no.2(bmp) to e-mail no.2

Any ideas? Thanks.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

David LeeConnect With a Mentor Commented:
I had a second look at the code from the other question and it looks to me like it will do what you want with minor modification.  The code I posted prints the open message and all attachments, so we need a modification that prints all selected messages, not just the open message.  The other issue is printing everything in sequence.  The messages will be handled in sequence and so will the attachments, but there is one factor I can't control.  Let's say a message has two attachments.  Attachment A is a Word document that's 20 pages long.  Attachment B is a small text file.  The code runs and prints the message then fires the command to print the Word document.  Word takes a moment to load and because the file is 20 pages long it's going to take several seconds to print.  In the meantime the code has moved along to the next attachment, the small text file, and ordered it to print.  The text file is probably going to appear before the Word document has finished.  I don't see any way to get around that.  There is no "tell an attachment to print and wait for it to finish before moving on" command.  I could through a Sleep command in to pause code execution immediately after the print, but that's not a good solution.  A large or complex document might take longer that then length of time I tell the code to sleep for, in which case we're back to having a problem, and items that print quickly will waste time while the code sleeps before printing the next item.  The only other approach would be to write a routine that would watch the queue of the printer the jobs are going to and watch for each one to finish before printing the next one.  That's possible, but it's certainly more complex and therefore more prone to problems.  Another alternative would be to pop up a dialog-box saying that attachment X has been sent to the printer and have you click a button to move on to the next item.  I expect that's not a good option.

Here's the modified code for printing all selected messages and their attachments.  Let me know how you'd like to proceed and we'll take it from there.

Sub PrintMessageAndAttachments()
    Dim objItem As Object, _
        objFile As Object, _
        strTempFolderPath As String, _
        strFilename As String, _
        objShellApp As Object, _
        objFolder As Object
    'Change the path on the next line to one that can hold temp files
    strTempFolderPath = "C:\eeTesting\Temp\"
    Set objShellApp = CreateObject("Shell.Application")
    Set objFolder = objShellApp.NameSpace(strTempFolderPath)
    For Each objItem In Application.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            For Each objFile In objItem.Attachments
                strFilename = strTempFolderPath & objFile.FileName
                objFile.SaveAsFile strFilename
                objFolder.ParseName(objFile.FileName).InvokeVerb ("&Print")
        End If
    Set objFile = Nothing
    Set objItem = Nothing
    Set objFolder = Nothing
    Set objShellApp = Nothing
End Sub
David LeeCommented:
Hi jrctl,

I can modify the code from this question ( to do this.  Is that what you're looking for?

jrctlAuthor Commented:
Hi again.

Hmmm maybe. I have a viewer that we possibly could use "C:\Program Files\Interwoven\WorkSite\view32.exe" that allows us to to view doc types. The problem with this app is that each document needs to be active in it in order to print out. i.e. you cannot select a range of documents and print the whole range.

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.

David LeeCommented:
Let me know how you want to proceed and we'll take it from there.
David LeeCommented:
Hi, jrctl.

Any progress?
jrctlAuthor Commented:
No, not as yet. I don't seem to be getting anywhere. The problem is if we set the viewer to be the deafult application it still doesn't get around the printing in order issue. We could try the viewer but I think that it will only solve one of the issues.
David LeeCommented:
What about modifying the code to the question I linked to?
jrctlAuthor Commented:
That was my original question as well! Yes, this could work but if only you can ensure the timing of the file openings. As it stands, your script converts all HTML e-mails to rich text and then prints of the e-mails with their linked attachments - which is great. The problem with this, however, is that there does not seem to be any mechanism to ensure that all attachments to   e-mail no.1 are printed out in order before e-mail no. 2 and it's attachments are printed out. If you can solve this then great!!!
David LeeCommented:
I pretty sure I can make it work that way.  I'll test to make sure and get back to you.
David LeeCommented:
Any update, jrctl?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.