VBA Outlook Mail .display,记录手动发送时/如果 [英] VBA Outlook Mail .display, recording when/if sent manually

查看:20
本文介绍了VBA Outlook Mail .display,记录手动发送时/如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码显示带有基本主题、正文、附件的消息.接下来,用户手动更新和自定义消息,并应该发送它.我想记录发送电子邮件的时间(如果).这可能吗或有什么提示吗?

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

希望有帮助...

这篇关于VBA Outlook Mail .display,记录手动发送时/如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆