Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: move email based on criteria - vba

  1. #1
    Board Regular
    Join Date
    Mar 2015
    Location
    Birmingham, West Midlands
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default move email based on criteria - vba

    Hi,

    I'm trying to create some code to move email based on various criteria within my inbox.

    The code needs to accomplish the following:


    • Move email from inbox to urgent subfolder based on senderemailaddress, listed in column A.
    • Move email from inbox to urgent subfolder based on a keyword found in senderemailaddress using a list of values located in column B. The code below attempts to find the name Smith in the address but it doesn't quite work for some reason.
    • Move email from inbox to urgent subfolder based on a keyword found in the email body using a list of values located in column C.


    Code:
    Sub UrgentEmail()
    
    'Use the Reference command on the Visual Basic for Applications (VBA) Tools menu
    'to set a reference to Microsoft Outlook xx.x Object Library,
    
        Dim olApp As Outlook.Application
        Dim olNS As Outlook.Namespace
        Dim olInBox As Outlook.MAPIFolder
        Dim olMoveToFolder As Outlook.MAPIFolder
        Dim olItems As Outlook.Items
    
        Set olApp = CreateObject("Outlook.Application")
        Set olNS = olApp.GetNamespace("MAPI")
        Set olInBox = olNS.GetDefaultFolder(olFolderInbox)
        Set olMoveToFolder = olInBox.Folders("Urgent")    'change the name of the subfolder accordingly
        Set olItems = olInBox.Items
        For Each MyEmail In olItems
            If InStr(MyEmail.SenderEmailAddress, "smith") > 0 Then
                olItems(MyEmail).Move olMoveToFolder
            End If
        Next MyEmail
        Set olApp = Nothing
        Set olNS = Nothing
        Set olInBox = Nothing
        Set olMoveToFolder = Nothing
        Set olItems = Nothing
    End Sub
    Thanks

  2. #2
    Board Regular
    Join Date
    Mar 2015
    Location
    Birmingham, West Midlands
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: move email based on criteria - vba

    Anyone please?

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
     


DMCA.com