用于在本地文件夹中保存电子邮件副本的 Outlook VBA 宏 [英] Outlook VBA macro for saving emails copies in a local folder

查看:27
本文介绍了用于在本地文件夹中保存电子邮件副本的 Outlook VBA 宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当发送电子邮件时,我都希望将该电子邮件的副本以及所有附件保存在本地文件夹中.

Whenever sending an email, I would like a copy of that email to be saved in the local folder, together with all attachments.

我认为 Outlook 中的自定义规则无法实现这一点,但也许可以使用 VBA 脚本来实现?

I don't think this is possible with a custom rule in Outlook but perhaps it could be done with a VBA script?

我使用 Outlook 和 MS Exchange.

I use Outlook and MS Exchange.

推荐答案

当然可以使用 Application_ItemSend 事件过程调用自定义过程来完成,该过程会将您发送的邮件保存到本地文件夹.

Sure it can be done using the Application_ItemSend event procedure to call a custom procedure which will save your sent mails to a local folder.

此代码位于ThisOutlookSession"模块中.

This code goes in "ThisOutlookSession" module.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Call SaveACopy(Item)
End Sub

Sub SaveACopy(Item As Object)
    Const olMsg As Long = 3

    Dim m As MailItem
    Dim savePath As String

    If TypeName(Item) <> "MailItem" Then Exit Sub

    Set m = Item

    savePath = "c:usersyour_user_namedesktop"  '## Modify as needed
    savePath = savePath & m.Subject & Format(Now(), "yyyy-mm-dd-hhNNss")
    savePath = savePath & ".msg"


    m.SaveAs savePath, olMsg


End Sub

你需要确保指定的路径是唯一的/等等,上面的例子相当粗糙.您还需要去除任何不能放在文件名中的非法字符(斜杠、管道等)...

You will need to ensure that the specified path is unique/etc., the above example is fairly crude. You also need strip out any illegal characters that can't be put in a file name (slash, pipes, etc.)...

作为替代方案,我建议您定期归档您的文件夹.您可以将 Outlook 配置为将已发送邮件的副本保存到已发送"文件夹,然后您应该能够对该文件夹进行存档;单独保存每个项目似乎不太理想.

As an alternative, I would suggest simply archiving your folder(s) periodically. You can configure Outlook to save a copy of sent mail to a "Sent" folder, and then you should be able to archive that folder; saving each item individually seems less-than-optimal.

这篇关于用于在本地文件夹中保存电子邮件副本的 Outlook VBA 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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