Solved

Segregating mails

Posted on 2004-08-10
5
427 Views
Last Modified: 2010-04-08
Hello Experts,
   I want to segregate mails that have the same date value in mail recieved date and mail sent date With the mails that have different values for these fields into different folders. Can you guide me as to how an I achieve this?
Rgds
Ovais
0
Comment
Question by:MOvais_Khan
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11771197
I think the only way to do this would be to write a MACRO that scan through your folder and compares each items DateValue(ReceivedTime) with the DateValue(SentOn) and if they match then moves them to a different folder.
0
 

Author Comment

by:MOvais_Khan
ID: 11772014
But how to write the macro, I dont have any experience in VB or VBA. Any reference material that I can study and implement this method. Also What will be the method (function) to move the mails to the seperate folder
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11772055
Something like this might work:

Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
0
 

Author Comment

by:MOvais_Khan
ID: 11772522
gives me debug error on the line
     If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then

Just Curious, Is this VBA, Can i have some study and reference material for VBA, as i have a lot of customizations that i think i can achieve with programming, so its better I learn about it
0
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 250 total points
ID: 11845056
Oops, I just realised I never got back to you on this. Sorry. Try assigning the dates to variables and then comparing them in the if statement like this:
****************************
Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
    Dim inDate As Date, outDate As Date
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        inDate = DateValue(oMessage.ReceivedTime)
        outDate = DateValue(oMessage.SentOn)
        If inDate = outDate Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
****************************

And yes this is VBA. I don't really know what to reccomend as far as study material. There are books available, but I personnaly have a hard time learning from books and prefer to learn by studying other peoples examples. There is a cool website that you might find useful:

http://www.outlookcode.com/code2.aspx?level=b


This book looks good:

http://www.pearsoned.co.uk/bookshop/detail.asp?item=100000000055448&affid=tre
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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

810 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