Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting an email when subject contains certain words

Tags:

email

vba

outlook

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

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.

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
like image 239
jperki39 Avatar asked Oct 19 '13 20:10

jperki39


People also ask

How do I delete an email in Outlook with the same subject?

1. Go to the email folder and select the email that you want to delete all emails which contain the same subject. 3. In the By Sender dialog box, you can choose to delete All emails with the same subject directly, or delete all emails with the same subject in a certain Date Range, and click the Delete button.

How do you delete an email with the same subject in Gmail?

Check the box in the top left corner to select all the emails that show. If you have more pages, you'll also see another link, “Select all messages that match this search.” Click the Delete icon.

How do I delete email keywords?

If you want to delete emails that contain specific keywords, enter them in the Has the words field. You can create as many filters as you want. These filters apply to new messages. If you want to delete old emails, the best solution is to filter them by date and delete them in batches.


1 Answers

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
like image 138
jperki39 Avatar answered Oct 07 '22 01:10

jperki39