通过VBA取消Outlook中的项目发送事件后关闭“发送邮件”窗口

通过VBA取消Outlook中的项目发送事件后关闭“发送邮件”窗口,vba,outlook,Vba,Outlook,我正在编写VBA宏,以防止向指定的电子邮件地址发送电子邮件。它是在ThisOutlookSession下运行的Outlook宏。代码运行正常,但问题是无法关闭“发送邮件”窗口 我添加了一行(在代码中标记),该行抛出一个错误“项。在项期间无法执行关闭命令。发送事件” 这是可以理解的,但我怎样才能克服呢 Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If Item.To = "some@doma

我正在编写VBA宏,以防止向指定的电子邮件地址发送电子邮件。它是在ThisOutlookSession下运行的Outlook宏。代码运行正常,但问题是无法关闭“发送邮件”窗口

我添加了一行(在代码中标记),该行抛出一个错误“项。在项期间无法执行关闭命令。发送事件”

这是可以理解的,但我怎样才能克服呢

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

 If Item.To = "some@domain.com" Then
     Prompt$ = "Are you sure you want to send this message?"
   If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
    Cancel = True

    Item.Close olDiscard          ' <<< ERROR HERE 

  End If
End If

End Sub
私有子应用程序\u ItemSend(ByVal项作为对象,取消作为布尔值)
如果项.To=”some@domain.com”“那么
提示$=“确实要发送此邮件吗?”
如果MsgBox(提示$,vbYesNo+vbQuestion+vbMsgBoxSetForeground,“发送前检查”)=vbNo,则
取消=真

Item.Close olDiscard'而不是关闭发送事件仍在运行时无法完成的项目本身,您可以关闭
项目检查器

见下文:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objInsp As Inspector
Dim Strmsg As String
Set objInsp = Item.GetInspector
If Item.To = "testmail@gmail.com" Then
    Strmsg = "Are you sure you want to send this message?"
    If MsgBox(Strmsg, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
        Cancel = True
        objInsp.Close 1
    End If
End If
End Sub

关闭
项目检查器
,而不是关闭发送事件仍在运行时无法完成的项目本身

见下文:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objInsp As Inspector
Dim Strmsg As String
Set objInsp = Item.GetInspector
If Item.To = "testmail@gmail.com" Then
    Strmsg = "Are you sure you want to send this message?"
    If MsgBox(Strmsg, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
        Cancel = True
        objInsp.Close 1
    End If
End If
End Sub

关闭
项目检查器
,而不是关闭发送事件仍在运行时无法完成的项目本身

见下文:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objInsp As Inspector
Dim Strmsg As String
Set objInsp = Item.GetInspector
If Item.To = "testmail@gmail.com" Then
    Strmsg = "Are you sure you want to send this message?"
    If MsgBox(Strmsg, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
        Cancel = True
        objInsp.Close 1
    End If
End If
End Sub

关闭
项目检查器
,而不是关闭发送事件仍在运行时无法完成的项目本身

见下文:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objInsp As Inspector
Dim Strmsg As String
Set objInsp = Item.GetInspector
If Item.To = "testmail@gmail.com" Then
    Strmsg = "Are you sure you want to send this message?"
    If MsgBox(Strmsg, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
        Cancel = True
        objInsp.Close 1
    End If
End If
End Sub

在VBA以外的语言中,您可以使用计时器-在ItemSend事件中启用计时器,当计时器事件触发时(此时您将退出ItemSend事件处理程序),禁用时间并关闭检查器


我不认为你可以在Outlook VBA中使用计时器,但是

在VBA以外的语言中,您可以使用计时器-在ItemSend事件中启用计时器,当计时器事件触发时(此时您将退出ItemSend事件处理程序),禁用时间并关闭检查器


我不认为你可以在Outlook VBA中使用计时器,但是

在VBA以外的语言中,您可以使用计时器-在ItemSend事件中启用计时器,当计时器事件触发时(此时您将退出ItemSend事件处理程序),禁用时间并关闭检查器


我不认为你可以在Outlook VBA中使用计时器,但是

在VBA以外的语言中,您可以使用计时器-在ItemSend事件中启用计时器,当计时器事件触发时(此时您将退出ItemSend事件处理程序),禁用时间并关闭检查器


我不认为你可以在Outlook VBA中使用计时器,但是

非常有用,我尝试使用inspector关闭它,但以另一种方式没有成功。谢谢你的帮助。非常有用,我试着用inspector关闭它,但用了另一种方式,但没有成功。谢谢你的帮助。非常有用,我试着用inspector关闭它,但用了另一种方式,但没有成功。谢谢你的帮助。非常有用,我试着用inspector关闭它,但用了另一种方式,但没有成功。谢谢你的帮助。