检测何时按下 SEND 按钮

Detecting when the SEND button is pressed

据我所知,在Outlook中发送mailitem有两种方式:

  1. 通过物理按下检查器中的发送按钮 window,或

  2. 通过宏命令执行MailItem.Send

我如何使用 Outlook 区分这些 VBA?

具体来说,我如何检测 SEND 按钮何时被按下?

能否修改 ItemSend() 以仅捕获此事件,而不捕获其他事件?

我不完全确定是否有办法检测物品的发送方式 - 但是,至少仍然有一种解决方法可以给您带来相同的效果。这将要求您在模块顶部创建一个布尔变量,在本例中我们使用 isVBA.

在事件处理程序中,您将添加一个 If Not isVBA 语句 - 每当您 手动 通过物理按下按钮发送项目时,这将是 True .

但是,在使用 MailItem.Send 方法的例程中,您将在发送发生之前的任何时间添加 isVBA = True - 这将告诉您的事件处理程序这不是 'manual'发送。

这是一个可视化表示:

Private isVBA As Boolean

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    If Not isVBA Then

        Rem: Do what you need to do with a MANUAL send

    End If

End Sub

Sub myVBASendMethod()

    ' Setting this to true will tell the event that you're using MailItem.Send
    isVBA = True

    ' Event Triggered using MailItem.Send

    ' Reset this back to false
    isVBA = False

End Sub