troubleshooting Question

Sort Outlook E-mail using VBCode.

Avatar of vb7guy
vb7guyFlag for United States of America asked on
Visual Basic Classic
4 Comments1 Solution173 ViewsLast Modified:
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
        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

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros