从文件夹删除电子邮件的代码 [英] Code to Delete Email from Folder

查看:104
本文介绍了从文件夹删除电子邮件的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为"请求"的文件夹。  我创建了一个Outlook规则,每当我应用"请求列表"时,都会将电子邮件的副本移动到此文件夹。 。类别 我的想法是使用此文件夹来管理需要大量
跟进的电子邮件。


完成跟进后,在收件箱中,我可以删除类别和类别也会自动从Request文件夹中的副本中删除。


我想要做的是创建一些东西,我认为是一个宏,它会自动从Requests文件夹中删除该电子邮件。 "请求列表"类别已被删除。


我对VBA没有太多经验,但如果有人可以共享可以实现此目的的代码,那就太棒了。

解决方案

您好,


您可以使用Items.ItemChange事件触发宏来删除Request文件夹中的复制邮件。您可以使用InStr方法确认邮件是否具有"请求列表"类别。

这是我的示例,您可以根据需要进行调整。


< pre class ="prettyprint">'在ThisOutlookSession中编写代码
Public WithEvents itm As Outlook.Items

Private Sub Application_Startup()
设置itm = Application.GetNamespace(" MAPI" ;)。GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub itm_ItemChange(ByVal Item As Object)
If Not InStr(Item.Categories," Request List")然后
Dim subj As String
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
subj = Item.Subject
设置objNS = Application.GetNamespace(" MAPI")
设置objFolder = objNS.Folders(" test@outlook.com")。文件夹(&"Custom")'test@outlook.com是你的account
For i = 1 to objFolder.Items.count
if objFo lder.Items.Item(i).Subject = Item.Subject然后
objFolder.Items.Remove(i)
退出
结束如果
下一个
结束If
结束子

问候,


Celeste




I created a folder called "Request".   I created an outlook rule to move a copy of an email to this folder whenever I apply the "Request List" category.  My idea is to use this folder to manage emails that require extensive follow up.

When the follow up is complete, in the inbox, I can remove the category and the category is also automatically removed from the copy in the Request folder.

What I would like to do is create something, a macro I assume, that automatically deletes that email from the Requests folder as soon as the "Request List" category is removed.

I do not have much experience with VBA but, if someone can share code that would accomplish this, that would be great.

解决方案

Hello,

You could use Items.ItemChange Event to trigger your macro for deleting the copy mail in Request folder. You could use InStr method  to confirm if the mail has the "Request List" category.
Here is my example and you could adjust it for your needed.

'Write code in ThisOutlookSession
Public WithEvents itm As Outlook.Items

Private Sub Application_Startup()
Set itm = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub itm_ItemChange(ByVal Item As Object)
If Not InStr(Item.Categories, "Request List") Then
    Dim subj As String
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objMail As Outlook.MailItem
    subj = Item.Subject
    Set objNS = Application.GetNamespace("MAPI")
    Set objFolder = objNS.Folders("test@outlook.com").Folders("Custom")   'test@outlook.com is your account
    For i = 1 To objFolder.Items.count
    If objFolder.Items.Item(i).Subject = Item.Subject Then
    objFolder.Items.Remove (i)
    Exit For
    End If
    Next
End If
End Sub

Regards,

Celeste


这篇关于从文件夹删除电子邮件的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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