Solved

Segregating mails

Posted on 2004-08-10
5
407 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
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.
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now