7

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
jperki39
  • 151
  • 1
  • 1
  • 4
  • 1
    See [THIS](http://stackoverflow.com/questions/8005713/using-vba-to-read-new-outlook-email) by @JimmyPena. Use this to capture the incoming mail and then delete it. – Siddharth Rout Oct 19 '13 at 20:30

1 Answers1

8

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
jperki39
  • 151
  • 1
  • 1
  • 4