Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

Segregating mails

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
MOvais_Khan
Asked:
MOvais_Khan
  • 3
  • 2
1 Solution
 
will_scarlet7Commented:
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
 
MOvais_KhanAuthor Commented:
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
 
will_scarlet7Commented:
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
 
MOvais_KhanAuthor Commented:
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
 
will_scarlet7Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now