Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Outlook Macro to delete emails not meeting keywords

Avatar of Jose Rivera-Hernandez
Jose Rivera-HernandezFlag for United States of America asked on
Visual Basic ClassicOutlookMicrosoft ApplicationsVB ScriptREST
55 Comments1 Solution509 ViewsLast Modified:
I have an Outlook (2010) Macro that sends emails with certain keywords in them to the "Deleted Items" bin.  What I would like now is an Outlook macro that will move emails having certain key words (account, ssn, credit) to another folder and the rest to the "Deleted Items" bin. All these emails come from a defined account.

see the code that I am using right now.

Function UnwantedMessage(olkMsg As Outlook.MailItem) As Boolean
    'On the next line edit the keywords/phrases you want to filter out.  Use the | character to separate each word/phrase
    Const KEYWORDS = "Address change completed|Thank you for your interest in employment |Ad|Internet Explorer 8 Settings"
    Dim olkAtt As Outlook.Attachment, objRegEx As Object, colMatches As Object
    Set objRegEx = CreateObject("VBscript.RegExp")
    With objRegEx
        .IgnoreCase = False
        .Pattern = KEYWORDS
        .Global = True
    End With
    For Each olkAtt In olkMsg.Attachments
        If IsHiddenAttachment(olkAtt) Then
            Set colMatches = objRegEx.Execute(olkAtt.FileName)
            If colMatches.Count > 0 Then
                UnwantedMessage = True
                Exit For
            End If
        End If
    Next
    Set olkAtt = Nothing
    Set objRegEx = Nothing
    Set colMatches = Nothing
End Function
ASKER CERTIFIED SOLUTION
Avatar of gowflow
gowflowFlag of Canada imagePartner

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 55 Comments.
See Answers