Consulting

Results 1 to 2 of 2

Thread: add a red flag to a email if the receiver's email is xxx.yahoo.com and yyy.yahoo.com

  1. #1

    add a red flag to a email if the receiver's email is xxx.yahoo.com and yyy.yahoo.com

    Hi,

    Could you please write the following macro?


    For each email in folder: inbox

    If the receiver’s email is xxx.yahoo.com and yyy.yahoo.com, then the email will have a red flag.

    Note: the email should be sent to both xxx.yahoo.com and yyy.yahoo.com, not either one of them.

    Thanks

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.
    i'm not an expert but googling and trial n error gave me this.
    i tested and it worked for my sample emails...
    i created a folder named "test", copied some emails there, only one meeting the criteria and used Set olFolder = olNS.PickFolder to select this folder.


    [vba]
    Sub VBAX_Flag_OLMails_Based_Recipients_Email()
    http://www.vbaexpress.com/forum/showthread.php?t=45174

    Dim olApp As Outlook.Application
    Dim olNS As NameSpace, olFolder As MAPIFolder
    Dim objMail As Object, objRecip As Object
    Dim arrRecip, FindMail1, FindMail2
    Dim i As Long
    Dim MatchCase As Boolean

    MatchCase = False
    FindMail1 = "xxx.yahoo.com"
    FindMail2 = "yyy.yahoo.com"
    C = Chr$(1)

    Set olApp = Outlook.Application
    Set olNS = olApp.GetNamespace("MAPI")
    Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
    'Set olFolder = olNS.PickFolder 'in order to pick the desired folder use this line.

    For Each objMail In olFolder.Items
    With objMail
    If .Class = olMail Then
    ReDim arrRecip(1 To .Recipients.Count)
    For i = 1 To .Recipients.Count
    arrRecip(i) = .Recipients(i)
    Next
    If InStr(1, C & Join(arrRecip, C) & C, C & FindMail1 & C, 1 + MatchCase) _
    And _
    InStr(1, C & Join(arrRecip, C) & C, C & FindMail2 & C, 1 + MatchCase) Then
    'http://www.mrexcel.com/forum/excel-questions/63296-visual-basic-applications-function-search-array.html#post2766823
    .FlagStatus = olFlagMarked
    .FlagIcon = 6
    .Save
    End If
    End If
    End With
    Next

    End Sub
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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