【发布时间】:2019-04-08 00:00:00
【问题描述】:
如何修改下面的代码来触发myMailItem_ItemSend事件,只有当邮件是myMacro1发送的,而其他情况下(比如myMacro2)不触发?
应该特别为那些使用 myMailItem 对象的宏触发事件。
Public WithEvents myMailItem As Outlook.MailItem
Public Sub Initialize_handler()
Set myMailItem = Outlook.MailItem
End Sub
Private Sub myMailItem_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Send confirmation") = vbNo Then
Cancel = True
End If
End Sub
'Should trigger the send confirmation msgbox
Private Sub myMacro1()
Dim objApp As Outlook.Application
Set objApp = Application
Set myMailItem = objApp.ActiveInspector.CurrentItem.ReplyAll
myMailItem.Display
End Sub
'Should NOT trigger the send confirmation msgbox
Private Sub myMacro2()
Dim objApp As Outlook.Application
Set objApp = Application
Dim oEmail As Outlook.mailItem
Set oEmail = objApp.ActiveInspector.CurrentItem.ReplyAll
oEmail.Display
End Sub
我们将不胜感激。
【问题讨论】:
-
您的意思是您希望事件
myMailItem_ItemSend仅在电子邮件由myMacro1()和myMacro2()发送时触发,而不是每次发送电子邮件时触发(即使是手动发送)? -
没有。仅适用于 myMacro1(),不适用于 myMacro2(),也不适用于默认的 Outlook 回复功能。
标签: vba events outlook mailitem