Send Email when Outlook Closes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for simple code that would send an email with the same
attachment and subject and recipient everytime I close down Outlook 2003. I
did this once before on my old machine, and do not have the code any longer.
Thanks!
 
Not sure what this means at all. I'm not talking about closing an explorer
window, and I am looking for the code to automate sending the email when
OUTLOOK closes. In other words, a module within Outlook that will execute
when outlook shuts down. Similar to a Auto_Close routine in Excel.
 
By the time you get any event such as Outlook.Quit or even the earlier
Explorer.Close on the last open Explorer, which is what Michael was talking
about, it's too late to use Outlook to send an email. You'd have to directly
address an SMTP server to send an email or something like that. It'd be way
to late to get Outlook to do it.
 
This has been done before though. I had it working. The new code I have this
time around is this:

Private Sub Application_Quit()

Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem

Set oApp = CreateObject("Outlook.Application")

Set oMail = oApp.CreateItem(olMailItem)

Set myAttachments = oMail.Attachments
myAttachments.Add "H:\Personal\To Do.doc", olByValue, 1, "Fichier"

oMail.To = "(e-mail address removed)"
oMail.Subject = "To Do List " & Format(Date, "DDD mm/dd/yy")

oMail.Send
' oApp.Quit
Set oApp = Nothing

End Sub

The commented out oApp.Quit so that It would send the mail, but now it just
stays in my outbox until the next time I open Outlook.
 
Actually, this CAN be done. I just added a msgbox at the end so that it would
give Outlook a second to get the message out of the outbox. I used a msgbox
that would only display for 2 seconds then close.

CreateObject("WScript.Shell").Popup "To-Do List Sent", 2, "Done!"
 
If it works for you great. I wouldn't instantiate an Outlook session inside
the Quit event myself. But that's up to you.
 
Back
Top