Outlook Tips For You

Rule is powerful tool to help you organize your email in Outlook, but sometimes, it still doesn’t meet your expectation, so anything else you could do? just wait Microsoft to add more features in next release of Outlook? I guess this isn’t what you expected. If you’re familiar with VBA, use Macro instead of Rule, because of the flexibility of VBA, you can hack it and custom it as you wish, I believe you’ll find out more advanced features of Outlook, even if you’re a newbie of VBA, it’s okay, VBA is not designed for geeks in the first place, you could get how to use it in several minutes, below is an example:

Sub BackupSentMail()
    Set OutApp = CreateObject("Outlook.Application")
    Set NmSpace = OutApp.GetNamespace("MAPI")
    Set BackupSent = NmSpace.Folders("Sent").Folders("ALL")
    Set DefaultSent = NmSpace.GetDefaultFolder(5)
    For intX = DefaultSent.Items.Count To 1 Step -1
        Set objMessage = DefaultSent.Items.Item(intX)
        objMessage.Move BackupSent
    Next

    Set OutApp = Nothing
    Set NmSpace = Nothing
    Set BackupSent = Nothing
    Set DefaultSent = Nothing
End Sub

Sub CustomMailMessageRule(Item As Outlook.MailItem)
    Set OutApp = CreateObject("Outlook.Application")
    Set NmSpace = OutApp.GetNamespace("MAPI")
    Set folderOnlyToMe = NmSpace.Folders("Main").Folders("OnlyToMe")
    Set folderTrash = NmSpace.Folders("Main").Folders("Trash")
    Set folderSWS = NmSpace.Folders("SWS").Folders("ALL")
    Set folderIntegration = NmSpace.Folders("Integration").Folders("ALL")
    Set folderIntegrationDev = NmSpace.Folders("Integration").Folders("Dev.")
    Set folderIncoming = NmSpace.Folders("Main").Folders("Incoming")
    ”””””””””””””””’
    ‘ Set Flag
    ”””””””””””””””’
    ‘ Sent by bosses
    If Item.SenderName = "Gates, Bill" Or _
        Item.SenderName = "Jackson, Michael" Or _
        Item.SenderName = "Jong, John" Then
        Item.FlagStatus = olFlagMarked
        Item.FlagIcon = olOrangeFlagIcon
        Item.Save
        MsgBox Item.Subject, vbInformation, "Here comes a new msg"
    End If
    ”””””””””””””””’
    ‘ Trash Filter
    ”””””””””””””””’
    If Item.SenderEmailAddress = "hqadmin@antispam.charry.org" Or _
        Item.SenderEmailAddress = "OPN_validation_system@antispam.charry.org" Or _
        Item.SenderEmailAddress = "MES_AUTO_LOT_HOLD@antispam.charry.org" Or _
        Item.SenderEmailAddress = "MTEPP_Detection_System@antispam.charry.org" Or _
        Item.SenderEmailAddress = "szcpp113@antispam.charry.org" Or _
        Item.SenderEmailAddress = "szcpp111@antispam.charry.org" Or _
        Item.SenderEmailAddress = "szcpp233@antispam.charry.org" Or _
        Item.SenderEmailAddress = "szcpp231@antispam.charry.org" Or _
        Item.SenderEmailAddress = "yammer@yammer.com" Or _
        Item.SenderEmailAddress = "Unfuse_units_detection_system@antispam.charry.org" Then
        Item.Move folderTrash
        GoTo CleanUp
    End If
    If Item.To = "fbdaemon@szasptgh101.amd.com" Then
        Item.Move folderTrash
        GoTo CleanUp
    End If
    ‘ SVN_INTDEV
    If InStr(Item.SenderEmailAddress, "@soulcutter.amd.com") > 0 Then
        Item.Move folderTrash
        GoTo CleanUp
    End If
    ‘ EDA Daily Report
    If Item.SenderEmailAddress = "The_Software_Services_Team@antispam.charry.org" Then
        Item.Move NmSpace.Folders("Misc").Folders("EDA Report")
        GoTo CleanUp
    End If
    ‘ Title Filter
    If InStr(Item.Subject, "ex-factory utilization report") > 0 Then
        Item.Move folderTrash
        GoTo CleanUp
    End If
    ”””””””””””””””’
    ‘ Normal Filter
    ”””””””””””””””’
    ‘ to me
    MyPos = InStr(Item.To, "Charry")
    If MyPos > 0 Then
        Item.Move folderOnlyToMe
        GoTo CleanUp
    End If
    ‘ cc me
    MyPos = InStr(Item.CC, "Charry")
    If MyPos > 0 Then
        Item.Move folderOnlyToMe
        GoTo CleanUp
    End If
    ‘ to dl.suz_sws
    MyPos = InStr(Item.To, "dl.suz_sws")
    If MyPos > 0 Then
        Item.Move folderSWS
        GoTo CleanUp
    End If
    ‘ cc dl.suz_sws
    MyPos = InStr(Item.CC, "dl.suz_sws")
    If MyPos > 0 Then
        Item.Move folderSWS
        GoTo CleanUp
    End If
    ‘ GMail
    If Item.To = "hi@antispamp.charry.org" Or Item.To = "charrywong@ggggggmail.com" Then
        Item.Move NmSpace.Folders("Misc").Folders("charry.org")
        GoTo CleanUp
    End If
    Item.Move folderIncoming
CleanUp:
    Set OutApp = Nothing
    Set NmSpace = Nothing
    Set folderOnlyToMe = Nothing
    Set folderTrash = Nothing
    Set folderSWS = Nothing
    Set folderIntegration = Nothing
End Sub

Sub CustomMeetingRequestRule(Item As Outlook.MeetingItem)
   MsgBox "Meeting request arrived: " & Item.Subject
End Sub

How do we activate the code above? first of all, you should create a macro in Visual Basic Editor(press ALT+F11 to call this editor), afterwards, paste the code above to the editor and save, then you need to create a rule and make the rule applies to all emails(there’s a time span option in wizard, you could set the new rule for all email received before year 2099), then you’ll see an option to let you run a script when you received an email, the following steps are straightforward.

The code snippet I posted here is just a reference, Google VBA+Outlook, you will get more examples. Focus on the email itself rather than organizing email. See, you’re just one step away from an effective and efficient working way.

Leave a Reply