2

我的代码显示一条带有基本主题、正文、附件的消息。接下来,用户手动更新和自定义消息并发送它。我想记录何时(如果)发送电子邮件。这是可能的还是任何提示?

我的环境是 Office 2007,带有一个基于 excel 的宏到 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
4

1 回答 1

4

这完全有可能,使用 Outlook.MailItem 类中的 _Send 事件。

我使用它的方式是创建一个名为 EMail Watcher 的类,因此当我创建电子邮件并执行 .Display 时,然后我创建一个新的 EMailWatcher 对象并告诉它监视该电子邮件以进行发送,然后在它发生时报告。

这是我使用的课程。基本上,我还可以选择设置 BoolRange,这样如果用户发送电子邮件,Excel 范围就会更新为 True。我还可以让班级在发送电子邮件时更新 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

希望这会有所帮助...

于 2010-03-29T19:43:36.947 回答