vba从发送的文件夹中删除电子邮件

问题描述:

我想在用规则转发电子邮件后从“已发送邮件”文件夹中删除一封电子邮件。vba从发送的文件夹中删除电子邮件

我试图从另一个帖子使用“brettdj”代码:Macro to delete an email,但它根本不适用于我。

我在找什么,它是一个vba宏,当您使用规则运行脚本时,它可以删除电子邮件。

任何想法如何,我可以做到了这一点

在此先感谢

+0

是否所有帐户都在同一个Outlook下? – 0m3r

+0

是的,所有帐户都是从相同的展望会话中提取的。 – Driven

+0

你已经使问题的答案无效,而不是可能接受它,如果它是正确的。人们不会喜欢这种行为。回滚这个问题,并问一个新的问题。 http://stackoverflow.com/help/someone-answers – niton

您没有在您的联系人文件夹(通讯录)中的相应条目。 Recipients类的Add方法接受收件人的名称;它可以是表示收件人的显示名称,别名或完整SMTP电子邮件地址的字符串。

Sub forwardEmail(itm As Outlook.MailItem) 
    Dim oExplorer As Outlook.Explorer 
    Dim oMail As Outlook.MailItem 
    Dim oOldMail As Outlook.MailItem 
    Set oExplorer = Application.ActiveExplorer 
    If oExplorer.Selection.Item(1).Class = olMail Then 
    Set oOldMail = oExplorer.Selection.Item(1) 
    Set oMail = oOldMail.Forward 
    oMail.Recipients.Add "[email protected]" 
    oMail.Recipients.Item(1).Resolve 
    If oMail.Recipients.Item(1).Resolved Then 
     'delete forwarded email from sent items 
     oMail.DeleteAfterSubmit = True 

     oMail.Send 
     'delete original email from inbox 
     'oOldMail.Delete 
    Else 
     MsgBox "Could not resolve " & oMail.Recipients.Item(1).Name 
    End If 
    Else 
    MsgBox "Not a mail item" 
    End If 
End Sub 
+0

感谢您的更新我有55个收件人,以及这将是一个挑战,我认为宏默认是这样做的任何转发电子邮件,没有任何选项没有接收者将会好得多。 – Driven

+0

我试过了,它不起作用,我在报价单中添加了一封电子邮件,但它并未在转发电子邮件后从发送文件夹中删除电子邮件。 – Driven