The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook.
VB Code:
  1. Dim WithEvents myOlApp As Outlook.Application
  2.  
  3. Sub Initialize_handler()
  4.     Set myOlApp = CreateObject("Outlook.Application")
  5. End Sub
  6.  
  7. Private Sub myOlApp_NewMail()
  8.     MsgBox "New mail has arrived, you lucky thing"
  9. End Sub