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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With