1

I'm working with outlook 2003

I search a way to get the event when a new mail is created (when the window of new mail is created)

Note: I search every way to add a menu to new mail window)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
forX
  • 2,063
  • 2
  • 26
  • 47

1 Answers1

4

This sample code should be placed in the ThisOutlookSession module. Restart Outlook and whenever you create a new email you will see the message box.

Private WithEvents objinspectors As Outlook.Inspectors

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

Private Sub objinspectors_NewInspector(ByVal Inspector As Inspector)
  If TypeName(Inspector.CurrentItem) = "MailItem" Then
    MsgBox "newinspector"
  End If
End Sub
JimmyPena
  • 8,694
  • 6
  • 43
  • 64
  • tank you. I had succeed with a dummy mail, I will check your code Dim outl As Object Dim mes As Object Set outl = CreateObject("Outlook.Application") Set mes = outl.CreateItem(0) mes.Display (False) mes.Close 1 – forX Nov 03 '11 at 17:15
  • You're welcome, where it says "Msgbox newinspector" you should put the code that does whatever you want to do when a new message is created. – JimmyPena Nov 03 '11 at 18:03
  • did you know a way to get a "moving item" event (move email like from inbox to MyPriorityFolder) – forX Nov 03 '11 at 19:53
  • Yes, but you should probably open a new question and I or someone else can answer it. – JimmyPena Nov 03 '11 at 20:21
  • The problem I have with office 2016/o365 is that the code is also fired if I open an existing item not only when I create a new one. Any idea how to thix? – Thierry Dalon May 10 '19 at 20:40