Consulting

Results 1 to 3 of 3

Thread: Outlook Find Emails with multiple criteria

  1. #1
    VBAX Regular
    Joined
    Oct 2006
    Location
    Columbus, GA
    Posts
    42
    Location

    Outlook Find Emails with multiple criteria

    I have searched the forum and cannot find an answer.

    I am pretty good with VBA, but I do not understand Outlook VBA. I need help with the following problem:

    Inbox has 148 items.

    Need to pull oldest email with the word “Urgent” or “Rush” or “Escalation” anywhere in the subject line and the email is unread.

    Outlook 2010 on Windows 7.

    Any help and guidance will be greatly appreciated.

    Lawson

  2. #2
    In that case you need to sort the inbox message collection in reverse date order and process the resulting list e.g.

    Dim olItems As Outlook.Items
    Dim olItem As Outlook.MailItem
    Dim i As Long
    
        'add the inbox content to the Items collection
        Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
        'Sort the collection in reverse order
        olItems.Sort "[Received]", False
        'Process each message from last to first
        For i = 1 To olItems.Count
            Set olItem = olItems(i)
            'Check if the message is unread
            If olItem.UnRead = True Then
                'Check if the subject contains one of the key words
                If InStr(1, olItem.subject, "Urgent") > 0 Or _
                   InStr(1, olItem.subject, "Rush") > 0 Or _
                   InStr(1, olItem.subject, "Escalation") > 0 Then
                    'do something with olitem here
                End If
            End If
        Next i
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Oct 2006
    Location
    Columbus, GA
    Posts
    42
    Location
    This works great! Thanks Graham for your quick response and help.

    Lawson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •