Results 1 to 14 of 14

Thread: [vba] Check outlook CC for domain & subject phrase

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Quote Originally Posted by gmayor View Post
    If the Move doesn't work then either the Vendor folder doesn't exist or it is not where the macro expects it to be. What is the path of the folder?
    it is a subfolder of the inbox. I will try the macro again and see if it still occurs.

    Quote Originally Posted by gmayor View Post
    The macro uses case statements so if any of those statements is true, the test will be true.
    So if it detects "gmail com" in the cc but does NOT contain ST26 in the subject line it will still move the email? I'm more looking to combine those two things as true

    Must be true:
    1. The subject contains ST26
    2. One or more of the 3 email options (gmail, msn, outlook) is in the To or CC fields

    so would this work?

    Sub CheckAndMoveMail(olItem As MailItem)
    Dim olFolder As Folder
    Dim x As Long
    
    If TypeName(olItem) = "MailItem" Then
    With olItem
    
    Select Case True
    Case InStr(1, .CC, "gmail com") > 0
           x = 1
    Case InStr(1, .CC, "msn com") > 0
           x = 1
    Case InStr(1, .CC, "outlook com") > 0
           x = 1
    Case InStr(1, .To, "gmail com") > 0
           x = 1
    Case InStr(1, .To, "msn com") > 0
           x = 1
    Case InStr(1, .To, "outlook com") > 0
           x = 1
    Case InStr(1, UCase(.Subject), "ST26") > 0
           x = x + 1
    End Select
    
        If x = 2 Then
            Set olFolder = Session.GetDefaultFolder(olFolderInbox).Folders("Vendor")
            olItem.Move olFolder
            olItem.UnRead = True
        End If
            End With
        End If
    lbl_Exit:
        Set olFolder = Nothing
        Exit Sub
    End Sub
    that way if any of the emails are found x = 1 and then if ST26 is found x = 2 but if ST26 isnt found x = 1 or x = 0 would not move the mail
    Last edited by Data Blake; 04-13-2020 at 07:59 AM.

Posting Permissions

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