Sort Emails by Date Received

jonnathanjons
Lounger
Posts: 37
Joined: 13 Apr 2023, 09:08

Sort Emails by Date Received

Post by jonnathanjons »

Dear Team,
Can you help me to create a Macro to Sort email by Column "Received" so I can see the latest email received in the inbox when I hit this macro button. Currently I have to manually hit receive and then Scroll to Top manually to see the latest email.
Instead I would like to have a Macro button created so I can see the latest email received in the active folder -inbox and Scroll To Top and Select the latest email received. I hope the experts here can easily create a macro. I am surprised why MS does not have this feature installed as a default. Please see the screenshot attached.

User avatar
HansV
Administrator
Posts: 79436
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort Emails by Date Received

Post by HansV »

Welcome to Eileen's Lounge!

You also posted this here.
If you ask the same question in multiple forums (called cross-posting), it is polite to mention that, with links to the other topics.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 79436
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort Emails by Date Received

Post by HansV »

You may get a better reply on Slipstick.com, but as far as I know, it's not easy to sort items visually using VBA. I might be wrong though.
It is possible to open the most recent message in the active folder:

Code: Select all

Sub OpenLatest()
    Dim fld As Folder
    Dim itms As Items
    Dim itm As MailItem
    On Error GoTo ErrHandler
    If TypeName(ActiveWindow) = "Explorer" Then
        Set fld = ActiveExplorer.CurrentFolder
        If fld.DefaultItemType <> olMailItem Then
            MsgBox "This is not an email folder!", vbExclamation
            Exit Sub
        End If
        Set itms = fld.Items
        If itms.Count = 0 Then
            MsgBox "This folder is empty!", vbExclamation
            Exit Sub
        End If
        itms.Sort "[ReceivedTime]", True
        If TypeName(itms.Item(1)) <> "MailItem" Then
            MsgBox "The most recent item is not an email message!", vbExclamation
            Exit Sub
        End If
        Set itm = itms.Item(1)
        itm.Display
    Else
        MsgBox "Please activate the main Outlook window, then try again!", vbExclamation
    End If
    Exit Sub
ErrHandler:
    Select Case Err.Number
        Case -2147352567
            MsgBox "The items in this folder cannot be sorted by received time!", vbExclamation
        Case Else
            MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation
    End Select
End Sub
Best wishes,
Hans

jonnathanjons
Lounger
Posts: 37
Joined: 13 Apr 2023, 09:08

Re: Sort Emails by Date Received

Post by jonnathanjons »

Thanks for the reply and the code provided.

I checked the script and it opens the latest email received. But I would like to see the email sorted by Date Received. It may be in a different view currently. For example it may be in sort by "subject" or by "From" currently . but as I run the macro it should change the format to sort by "Received" and should scroll to the Top

Yes I have posted this in other forums but as you see that I did not get any response for this request.

User avatar
HansV
Administrator
Posts: 79436
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort Emails by Date Received

Post by HansV »

I'm afraid I don't know if it is possible to change the order in which messages are displayed, and if so, how.
Best wishes,
Hans

JoeP
SilverLounger
Posts: 2133
Joined: 25 Jan 2010, 02:12

Re: Sort Emails by Date Received

Post by JoeP »

While it is not a macro you can do this simply by selecting the folder you want, changing the sort order to "Date (Conversation)" with "newest on top" if the view is something different, and then hitting the Home key. No need to scroll.
Joe

jonnathanjons
Lounger
Posts: 37
Joined: 13 Apr 2023, 09:08

Re: Sort Emails by Date Received

Post by jonnathanjons »

Thanks for the reply. I Understand that a vb script is difficult ..I currently have the sort order Newest On Top as you mentioned. but the challenge is when the current sort is different than the "Received" I have to hit received first and then "Newest to the Top". But I can live with it until some one come up with a script which does both in a single run..Thanks again team..