VBA Outlook Mail .display,记录何时/如果手动发送 [英] VBA Outlook Mail .display, recording when/if sent manually
问题描述
我的代码显示一条带有基本主题,正文和附件的消息.接下来,用户手动更新和自定义消息,然后将其发送.我想记录发送电子邮件的时间.这可能或任何提示吗?
My code displays a message with basic subject, body, attachment. Next the user manually updates and customizes the message and should send it. I want to record when (if) the email is sent. Is this possible or any tips?
我的环境是Office 2007,带有一个基于Excel的宏,可用于Outlook.
My environment is Office 2007 with an excel based macro going to Outlook.
[摘录]
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事件,这完全有可能.
This is entirely possible, using the _Send event in the Outlook.MailItem class.
使用它的方式,我创建了一个名为EMail Watcher的类,因此,当我创建电子邮件并执行.Display时,然后创建一个新的EMailWatcher对象,并告诉它监视该电子邮件以进行发送,然后在返回时进行报告.它发生了.
The way I use it, I create a class called EMail Watcher, so when I create the email and do the .Display, I then create a new EMailWatcher object and tell it to watch that email for send, then report back when it happens.
这是我使用的班级.基本上,我还可以选择设置BoolRange,以便如果用户发送电子邮件,则Excel范围将更新为True.我还可以让班级在发送电子邮件时更新Excel范围.
Here's the class as I use it. Basically, I also optionally can set the BoolRange so that if the user sends the email, that Excel range gets updated with True. I can also have the class update an Excel range with the time the email is sent.
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
希望这对您有帮助...
Hopefully that helps...
这篇关于VBA Outlook Mail .display,记录何时/如果手动发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!