Search code examples
vbaoutlookoutlook-2003

Fire an Outlook 2003 macro when the user creates a new blank message


I found events that fire when the user receives a message, or hits the send button, but nothing that fire when the user creates a blank, new email.


Solution

  • You should be able to use the NewInspector event. Example:

    Public WithEvents myOlInspectors As Outlook.Inspectors
    
    Private Sub Application_Startup()
        Initialize_handler
    End Sub
    
    Public Sub Initialize_handler()
        Set myOlInspectors = Application.Inspectors
    End Sub
    
    Private Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
        Dim msg As Outlook.MailItem
        If Inspector.CurrentItem.Class = olMail Then
            Set msg = Inspector.CurrentItem
    
            If msg.Size = 0 Then
                MsgBox "New message"
            End If
        End If
    End Sub