?
Solved

Need a script to organize my mails in Outlook

Posted on 2014-11-06
2
Medium Priority
?
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

801 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