【发布时间】:2018-11-14 01:41:52
【问题描述】:
当运行时在 ItemSend() 事件中发生错误时,将发送 Outlook 邮件项。在代码中放置Cancel = True 甚至不能阻止这种情况的发生。这是 VBA 固有的缺陷吗?
我将如何解决这个问题?欢迎任何想法。
Public WithEvents myApp As Outlook.Application
Sub Initialize_handler()
Set myApp = Application
End Sub
Private Sub myApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo ErrorHandler_myApp_ItemSend
Cancel = True
' Do something erroneous
Exit Sub
ErrorHandler_myApp_ItemSend:
Cancel = True
MsgBox "Error: " Err.Description
Err.Clear
End Sub
【问题讨论】:
-
在两个 Cancel = True 行上放置一个断点,然后运行您的代码。代码是否到达?
-
如果所有这些代码都在 ThisOutlookSession 中,您是否可以通过删除前四行并更改为
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)来编辑问题以消除不必要的复杂情况。你会输入Err.Raise,这样潜在的受访者就不会引入试图制造错误的错误。 -
nitro@ 感谢您的提示。
标签: vba events outlook onerror