"autoopen" or its equivalent?

  • Thread starter Thread starter DJ Kim
  • Start date Start date
D

DJ Kim

I'd like to write a macro that runs automatically when I open an
e-mail, equivalent to Word's "autoopen".
Can this be done with Outlook?

The purpose is to check the encoding, and if it's unicode, to turn it
to my local country encoding. (otherwise the mail gets garbbled when i
reply to a unicode message.)
 
If you paste this code into your ThisOutlookSession module, you will get a
handle to the open event whenever an existing e-mail is opened; put whatever
code you need into the objMyMail_Open event.

Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objMyAppointment As Outlook.AppointmentItem
Dim WithEvents objMyMail As Outlook.MailItem
Dim WithEvents objMyContact As Outlook.ContactItem
Dim WithEvents objMyTask As Outlook.TaskItem
'...etc.

Private Sub Application_Quit()
Set objInspectors = Nothing
Set objMyAppointment = Nothing
Set objMyContact = Nothing
Set objMyMail = Nothing
Set objMyTask = Nothing
End Sub

Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
Select Case Inspector.CurrentItem.Class
Case olAppointment
Set objMyAppointment = Inspector.CurrentItem
Case olMail
Set objMyMail = Inspector.CurrentItem
Case olContact
Set objMyContact = Inspector.CurrentItem
Case olTask
Set objMyTask = Inspector.CurrentItem
End Select
End Sub

Private Sub objMyMail_Open(Cancel As Boolean)
'do stuff when this happens
End Sub
 
Back
Top