Vba 当用户创建新的空白邮件时触发Outlook 2003宏

Vba 当用户创建新的空白邮件时触发Outlook 2003宏,vba,outlook,outlook-2003,Vba,Outlook,Outlook 2003,我发现当用户收到消息或点击发送按钮时会触发事件,但当用户创建一封空白的新电子邮件时不会触发任何事件。您应该能够使用NewInspector事件。例如: Public WithEvents myOlInspectors As Outlook.Inspectors Private Sub Application_Startup() Initialize_handler End Sub Public Sub Initialize_handler() Set myOlInspecto

我发现当用户收到消息或点击发送按钮时会触发事件,但当用户创建一封空白的新电子邮件时不会触发任何事件。

您应该能够使用NewInspector事件。例如:

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

在我启用宏之后,这项功能运行得非常好。Outlook 2003中的“高”安全设置甚至不允许您运行未签名的宏,因此切换到“中”就成功了。