【问题标题】:Detecting when the SEND button is pressed检测何时按下 SEND 按钮
【发布时间】:2018-11-16 00:42:09
【问题描述】:

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

  1. 通过物理按下 Inspector 窗口中的 SEND 按钮,或

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

如何使用 Outlook VBA 区分这些?

具体来说,如何检测何时按下发送按钮?

可以修改ItemSend() 以仅捕获此事件而不捕获其他事件吗?

【问题讨论】:

  • 可能会添加一些mousse事件的跟踪,这样你就知道最后一次点击鼠标是什么时候了。 (使用键盘时不起作用)

标签: vba button outlook send


【解决方案1】:

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

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

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

这是一个视觉表示:

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

【讨论】:

  • @K.戴维斯我认为你的解决方案可以很好地解决手头的问题。谢谢。
猜你喜欢
  • 1970-01-01
  • 2021-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多