我想知道是否有办法按日期对电子邮件进行排序,然后打开最新的电子邮件。
我正在尝试搜索Body内部具有唯一标记的电子邮件。为了避免重复的电子邮件具有相同的标签,我必须按日期对这些电子邮件进行排序,并打开最新的电子邮件,以便我可以回复它。
答案 0 :(得分:5)
您需要在Sort属性上发送ReceivedTime封电子邮件,该电子邮件会返回一个日期,指明收到该项目的日期和时间。
Sub SortByDate()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myItem As Outlook.MailItem
Dim myItems As Outlook.Items
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
myItems.Sort "[ReceivedTime]"
For Each myItem In myItems
MsgBox myItem.Subject & " ---- " & myItem.ReceivedTime
Next myItem
End Sub
答案 1 :(得分:0)
对于MS Outlook 2010及更高版本,请使用Items.Sort方法。
Sub SortByDueDate()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myItem As Outlook.TaskItem
Dim myItems As Outlook.Items
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
myItems.Sort "[DueDate]", False
For Each myItem In myItems
MsgBox myItem.Subject & "-- " & myItem.DueDate
Next myItem
End Sub
对于以前的版本,请参阅:Sorting Items in a Folder