我的代码显示一 strip 有基本主题、正文和附件的消息。接下来,用户手动更新和自定义消息并发送它。我想记录电子邮件何时发送。这可能吗?或者有什么提示吗?
我的环境是 Office 2007,带有一个用于 Outlook 的基于 Excel 的宏。
[摘录]
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = Email '.CC =
.Subject = Subj
.BodyFormat = olFormatHTML
.Body = Msg '.HTMLBody = Msg
If Not FileAttach = vbNullString Then .Attachments.Add (FileAttach)
.Display
End With
最佳答案
使用 Outlook.MailItem 类中的 _Send 事件,这是完全可能的。
我使用它的方式,我创建一个名为 EMail Watcher 的类,因此当我创建电子邮件并执行 .Display 时,我然后创建一个新的 EMailWatcher 对象并告诉它监视该电子邮件的发送,然后在何时报告它发生了。
这是我使用的类(class)。基本上,我还可以选择设置 BoolRange,以便如果用户发送电子邮件,该 Excel 范围就会更新为 True。我还可以让类(class)根据发送电子邮件的时间更新 Excel 范围。
Public BoolRange As Range
Public DateRange As Range
Public WithEvents TheMail As Outlook.MailItem
Private Sub TheMail_Send(Cancel As Boolean)
If Not BoolRange Is Nothing Then
BoolRange.Value = True
End If
If Not DateRange Is Nothing Then
DateRange.Value = Now()
End If
End Sub
这是我的使用方法:
With oMail
.To = addr
.Subject = "CCAT eVSM Utilities License Code"
.Body = "Message body"
.Display
End With
Set CurrWatcher = New EmailWatcher
Set CurrWatcher.BoolRange = Range("G12")
Set CurrWatcher.TheMail = oMail
希望有帮助...
关于VBA Outlook Mail.显示,记录何时/如果手动发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2533066/