Outlook VBA保存副本已发送项目 [英] Outlook VBA Save Copy Sent Item

查看:113
本文介绍了Outlook VBA保存副本已发送项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一段Outlook-vba代码,该代码将已发送邮件的副本保存在特定的文件夹中.按下发送"时,代码被触发.

I'm writing a piece of Outlook-vba code that saves a copy of a sent mail item in a specific folder. The code is fired when hitting "send".

以下代码有效,但是该项目作为UNSENT Email项目保存在文件夹中(外观显示消息:此消息尚未发送").我希望将它作为已发送邮件保存在我的文件夹中(就像文件夹已​​发送邮件"一样).

The below code is working, however the item is saved in the folder as an UNSENT Email item (outlook shows the message: "This message has not been sent"). I want it saved in my folder as a sent item (just like the folder "sent items").

请您对以下代码发表评论:

Could you please comment on the code below:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo ErrorHandler

Dim moveToFolder As Outlook.MAPIFolder
Dim myCopiedItem As Outlook.MailItem

Set ns = Application.GetNamespace("MAPI")
Set moveToFolder = ns.Folders("Mailbox - My Mailbox").Folders(".Waiting_for")


With Item

    If InStr(Item.Body, "/wf") > 0 Then

         Set myCopiedItem = Item.copy

            myCopiedItem.Move moveToFolder

    Else
    End If

End With

Exit Sub
ErrorHandler:
    MsgBox "Error!"
End Sub

推荐答案

当ItemSend事件触发时,该消息尚未提交(您可以将Cancel参数设置为true).最早可以看到已发送状态的消息是在已发送邮件"文件夹上触发Items.ItemAdd事件时.

When ItemSend event fires, the message has not been submitted yet (you can set the Cancel parameter to true). The earliest you can see the message in the sent state is when the Items.ItemAdd event fires on the Sent Items folder.

为什么不简单地设置MailItem.SaveSentMessageFolder属性?发送邮件后,Outlook将自动移动该邮件.唯一的限制是该文件夹必须位于创建消息的同一存储中.

Why not simply set the MailItem.SaveSentMessageFolder property? Outlook will automatically move the message after it is sent. The only limitation is that the folder must be in the same store where the message was created.

这篇关于Outlook VBA保存副本已发送项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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