Link to home
Start Free TrialLog in
Avatar of vb7guy
vb7guyFlag for United States of America

asked on

Sort Outlook E-mail using VBCode.

I have project which reads new E-mails and Download attachments. I'm using Outlook Object. Everyting works fine except I need to make faster by sorting the E-mail by UnRead E-mail. I'm going through loop of Email item, here is the sample code.  Now, How would sort all my E-mail so that all UnRead E-mail show up first. So I only go through UnRead E-mails only.


Private Sub ReadMail(as_SenderName As String)
Dim oOUTLOOK As Outlook.Application    'Set myOlApp = CreateObject("Outlook.Application")
Dim oNamespace As Outlook.NameSpace
Dim myFolder As MAPIFolder
Dim ls_File As String
     
    Set oOUTLOOK = New Outlook.Application
    Set oNamespace = oOUTLOOK.GetNamespace("MAPI")
    Set myFolder = oNamespace.GetDefaultFolder(olFolderInbox)
    For Each myItem In myFolder.Items
        DoEvents
        If myItem.SenderName = as_SenderName Then
            If myItem.UnRead = True Then
                If myItem.Attachments.Count > 0 Then
                    ls_File = App.Path & "\" & myItem.Attachments.Item(1).FileName
                    myItem.Attachments.Item(1).SaveAsFile (ls_File)
                    Call gsb_OpenFile(Me, ls_File)
                   
                End If
            End If
        End If
    Next myItem

End Sub
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

I think that the close you could get is sorting by date, even UI hasn't a feature like that (neither an email program that i have been seen, by the way).
ASKER CERTIFIED SOLUTION
Avatar of PNJ
PNJ

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi vb7guy,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept PNJ's comment(s) as an answer.

vb7guy, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Avatar of vb7guy

ASKER

Sorry, I forgot about this question as I'm no longer working on this project.

Thanks for your Answer. I tried this on my test prject and It does work.

VB7GUY