vb7guy
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.Appl ication")
Dim oNamespace As Outlook.NameSpace
Dim myFolder As MAPIFolder
Dim ls_File As String
Set oOUTLOOK = New Outlook.Application
Set oNamespace = oOUTLOOK.GetNamespace("MAP I")
Set myFolder = oNamespace.GetDefaultFolde r(olFolder Inbox)
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) .SaveAsFil e (ls_File)
Call gsb_OpenFile(Me, ls_File)
End If
End If
End If
Next myItem
End Sub
Private Sub ReadMail(as_SenderName As String)
Dim oOUTLOOK As Outlook.Application 'Set myOlApp = CreateObject("Outlook.Appl
Dim oNamespace As Outlook.NameSpace
Dim myFolder As MAPIFolder
Dim ls_File As String
Set oOUTLOOK = New Outlook.Application
Set oNamespace = oOUTLOOK.GetNamespace("MAP
Set myFolder = oNamespace.GetDefaultFolde
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)
myItem.Attachments.Item(1)
Call gsb_OpenFile(Me, ls_File)
End If
End If
End If
Next myItem
End Sub
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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
Thanks for your Answer. I tried this on my test prject and It does work.
VB7GUY