vba 当主题包含某些词时删除电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19470564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:55:02  来源:igfitidea点击:

Deleting an email when subject contains certain words

vbaemailoutlookoutlook-vba

提问by jperki39

At work I use Microsoft Outlook, and I've run out of space for outlook rules.

在工作中,我使用 Microsoft Outlook,但 Outlook 规则的空间已用完。

I'm trying to create a VBA procedure that will check my email as I get it, and if there is a email with a specified string in the subject it will delete it.

我正在尝试创建一个 VBA 程序,它将在我收到电子邮件时检查我的电子邮件,如果有一封主题中包含指定字符串的电子邮件,它将删除它。

This is what I tried to code but I couldn't get it to work:

这是我尝试编写的代码,但无法使其正常工作:

Public Sub process_email(itm As Outlook.MailItem)
    Dim new_msg As MailItem

    If new_msg.subject Like "*keyword*" Then
        new_msg.Delete
    End If
End Sub

回答by jperki39

I got it to work:

我让它工作:

'deletes all emails with "Magic Carpet Ride" in the subject
        If InStr(itm.Subject, "Magic Carpet Ride") > 0 Then
            itm.UnRead = False
            itm.Save
            itm.Delete
            End
        End If