How do I use ItemAdd on the Sent Items folder?

◇◆丶佛笑我妖孽 提交于 2019-12-20 04:38:13

问题


This question looks like it should have been answered here: Outlook VBA Save Copy Sent Item

I am unable to find the referenced "Items.ItemAdd" event amongst the list of events in the VB Editor for Outlook 2016.

Application.ItemSend is located in "ThisOutLookSession". The script I came up with looks 90% similar to the one posted in the original question and I have the same problem. The mail item is saved in it's pre-send condition.

I can't use "MailItem.SaveSentMessageFolder" as I am trying to move the sent mail to a PST.

The Event is explained here: https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/items-itemadd-event-outlook

In case someone asks "Why not use the AutoArchive Function?", my organization has some terrible group policies set up for both Sent Items and AutoArchive. I can't wade through the mess to get AutoArchive for sent items set up.


回答1:


Work with Items.ItemAdd Event (Outlook)

Example

Option Explicit
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
    Dim olNs As Outlook.NameSpace
    Dim Inbox  As Outlook.MAPIFolder

    Set olNs = Application.GetNamespace("MAPI")
    Set Inbox = olNs.GetDefaultFolder(olFolderSentMail)
    Set Items = Inbox.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
    If TypeOf Item Is Outlook.mailitem Then
'        code to copy the sent Item here
    End If
End Sub


来源:https://stackoverflow.com/questions/48496150/how-do-i-use-itemadd-on-the-sent-items-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!