我正在使用以下代码来检索和检查电子邮件,但outlook正在从12/22开始返回邮件,这既不是最新的也不是最旧的,而在同事的机器上它收取最旧的邮件。
Set oapp = CreateObject("Outlook.Application")
Set oMAPI = oapp.GetNamespace("MAPI")
Set oInbox = oMAPI.GetDefaultFolder(6)
oInbox.Display
Set oallmails = oInbox.Items
Set oreqemail = oallmails.GetFirst
For oTotalmail = 1 To oallmails.Count
ostringmatch = oreqemail.Subject
'Using regex function to match
'If MatchString(ostringmatch,"89554 Completed") Then
'End If
'Exit For
Set oreqemail = oallmails.GetNext
Next
我错过了任何outlook设置,因为代码看起来不错。 感谢
答案 0 :(得分:1)
要确保始终在Outlook中获得最新或最旧的电子邮件,您需要使用Items类的Sort方法。它按指定的属性对项目集合进行排序。完成此方法后,集合的索引将重置为1。要排序的属性的名称,可以括在括号中,例如" [CompanyName]"。
注意,排序仅影响集合中项目的顺序。它不会影响资源管理器视图中项目的顺序。
Set oapp = CreateObject("Outlook.Application")
Set oMAPI = oapp.GetNamespace("MAPI")
Set oInbox = oMAPI.GetDefaultFolder(6)
oInbox.Display
Set oallmails = oInbox.Items
oallmails.Sort "[RecievedTime]"
Set oreqemail = oallmails.GetFirst
For oTotalmail = 1 To oallmails.Count
ostringmatch = oreqemail.Subject
'Using regex function to match
'If MatchString(ostringmatch,"89554 Completed") Then
'End If
'Exit For
Set oreqemail = oallmails.GetNext
Next
有关详细信息,请参阅Outlook VBA: How to sort emails by date and open the latest email found?。