"autoopen" or its equivalent?

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.)
 
E

Eric Legault [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top