Solved

Need a script to organize my mails in Outlook

Posted on 2014-11-06
2
213 Views
Last Modified: 2014-11-20
Hi Experts i found a script on http://www.slipstick.com/developer/delete-older-messages-new-message-arrives/

Sub DeleteOlderMessages(Item As Outlook.MailItem)
 
Dim objInbox As Outlook.MAPIFolder
Dim intCount As Integer
Dim objVariant As Variant
 
Set objInbox = Session.GetDefaultFolder(olFolderInbox)
 
' Remove these lines if you don't want to add a category
Item.Categories = "Delete Older"
Item.Save
 
For intCount = objInbox.Items.Count To 1 Step -1
 Set objVariant = objInbox.Items.Item(intCount)
 If objVariant.MessageClass = "IPM.Note" Then
    If objVariant.Subject = Item.Subject And objVariant.SentOn < Item.SentOn Then
     objVariant.Delete
     Else
    End If
 End If
Next
 
Set objInbox = Nothing
End Sub

This will delete Mails with the same subject. I am in the need for the similar situation but my subjects are in one word different.

Explaination: I am getting from nagios status mails. I can not access directly to the system so i need to keep track of the status. So my idea is to have a rule set like this:
1.) when mail arrive i move them to a folder named like the system
2.) if in the subject is ** PROBLEM then it should keep it
3.) if in the subject is ** RESOLVED it should remove both the ** Problem one and the ** RESOLVED one

Can someone help me out?
If necessary i can install a tool instead of the rules in Outlook. But i did not find any tool what is doing that.
I have no access to exchange itself so i need a client solution.
0
Comment
Question by:Wilder_Admin
2 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 40427548
So there will never be more than two messages in a given system's folder?
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40454001
The guts of what you need are here
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
   ' Reference the items in the Inbox. Because myOlItems is declared
   ' "WithEvents" the ItemAdd event will fire below.
   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
      ' Check to make sure it is an Outlook mail message, otherwise
      ' subsequent code will probably fail depending on what type
      ' of item it is.
      If TypeName(Item) = "MailItem" Then
            Select Case True
                 Case Item.Subject Like "** PROBLEM"
                      'code to move the item to a particular folder
                 Case Item.Subject Like "** RESOLVED"
                      'code to search a particular folder for an item with subject like "** PROBLEM"
                      'if found, that item is deleted and the resolved email is also deleted.
                 Case Else
                       'any code you may want to fire in the event of mailings without the critical words
        End Select
      End If
End Sub

Open in new window


If you need more help, more detail about the subjects of the items, and the folders will be required.
I can't code for what I have no information about.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question