Items.Count 代表的集合中的项目可以是最新的或最先收到的
Item in a collection represented by Items.Count can be the latest or the first to be received
我有在两台计算机上运行的代码。
Option Explicit
Public olApp As Outlook.Application
Public olNs As Outlook.NameSpace
Public olFldr As Outlook.MAPIFolder
Public olItms As Outlook.Items
Public myItms As Outlook.Items
Public myDestFolder As Outlook.Folder
Public olMail As Variant
Public i As Long
Public Sender As Outlook.AddressEntry
Public Number As Long
Public environment As String
Public MyObj As Object
Public MySource As Object
Public file As Variant
Public myFile As Variant
Public textline As Variant
Public Text As Variant
Public identifier As Boolean
Public j As Long
Public k As Long
Public counter As Long
Sub MySub()
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
Set myDestFolder = olFldr.Folders("Tradebook")
Set myItms = myDestFolder.Items
On Error GoTo ContinueHere2:
counter = olItms.Count
在我的电脑上,它将 olItms.Count 视为我收件箱中的最新电子邮件,即项目 20,000 是最新收到的电子邮件。
在我同事的计算机上,它将 olItms.Count 解释为收到的第一封电子邮件。
我需要理解为什么会发生这种情况,因为如果它在我不知道何时以及为何发生的情况下进行切换,那将是灾难性的。
使用项目 class 的 Sort 方法按指定的 属性 对项目集合进行排序。排序仅影响集合中项目的顺序。它不会影响资源管理器视图中的项目顺序。
Sub SortByRecievedDate()
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 "[RecievedTime]", False
For Each myItem In myItems
MsgBox myItem.Subject & "-- " & myItem.DueDate
Next myItem
End Sub
我有在两台计算机上运行的代码。
Option Explicit
Public olApp As Outlook.Application
Public olNs As Outlook.NameSpace
Public olFldr As Outlook.MAPIFolder
Public olItms As Outlook.Items
Public myItms As Outlook.Items
Public myDestFolder As Outlook.Folder
Public olMail As Variant
Public i As Long
Public Sender As Outlook.AddressEntry
Public Number As Long
Public environment As String
Public MyObj As Object
Public MySource As Object
Public file As Variant
Public myFile As Variant
Public textline As Variant
Public Text As Variant
Public identifier As Boolean
Public j As Long
Public k As Long
Public counter As Long
Sub MySub()
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
Set myDestFolder = olFldr.Folders("Tradebook")
Set myItms = myDestFolder.Items
On Error GoTo ContinueHere2:
counter = olItms.Count
在我的电脑上,它将 olItms.Count 视为我收件箱中的最新电子邮件,即项目 20,000 是最新收到的电子邮件。
在我同事的计算机上,它将 olItms.Count 解释为收到的第一封电子邮件。
我需要理解为什么会发生这种情况,因为如果它在我不知道何时以及为何发生的情况下进行切换,那将是灾难性的。
使用项目 class 的 Sort 方法按指定的 属性 对项目集合进行排序。排序仅影响集合中项目的顺序。它不会影响资源管理器视图中的项目顺序。
Sub SortByRecievedDate()
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 "[RecievedTime]", False
For Each myItem In myItems
MsgBox myItem.Subject & "-- " & myItem.DueDate
Next myItem
End Sub