Results 1 to 2 of 2
  1. #1
    JustCallMeAl
    Guest

    Print from Word Outlook Last E-Mail Sent

    I have no idea even where to start on this one....not really, but that is how I am feeling.

    From a Word 97 VBA procedure, I need to print the last sent e-mail sent by Outlook.

    This is part of a larger project where we can guarantee that the last e-mail sent by Outlook is the one we want.

    The printed product must look the same as if the user went to Outlook, Sent Items, and printed the last e-mail.

    Thanks for any assistance. I have no idea even how to head. The Outlook object is a mystery to me. [img]/forums/images/smilies/smile.gif[/img]

    Thanks.

  2. #2
    JustCallMeAl
    Guest

    Re: Print from Word Outlook Last E-Mail Sent

    Well after a lot of searching, I finally found a solution. This works in Word 2000 with Outlook 2000. I have my doubts if it will work in Outlook below 2000. Anyway, here it is. Hopefully it will assist someone else with an Outlook project. VBA in Outlook is very weird.

    <pre>Sub ShowLastSentMailItem()
    Dim objOutlook
    Dim objDoc
    Dim myNameSpace
    Dim MyLastSentMessage

    On Error Resume Next
    Set objOutlook = GetObject(, "Outlook.Application")
    If objOutlook Is Nothing Then
    Set objOutlook = CreateObject("Outlook.Application")
    End If
    On Error GoTo 0
    Set myNameSpace = objOutlook.GetNameSpace("MAPI")
    ' The 5 in the next line is for olFolderSentMail
    Set MyLastSentMessage = myNameSpace.GetDefaultFolder(5).items.getlast

    MyLastSentMessage.Display
    ' Rem the above line to not display the message.
    ' Remove rem from below line to print the message.
    ' MyLastSentMessage.PrintOut

    Set objDoc = Nothing
    Set objOutlook = Nothing
    Set myNameSpace = Nothing
    Set MyLastSentMessage = Nothing

    End Sub</pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •