您好我在Outlook 2013中使用vba创建宏,我需要将mi收件箱中的las消息(最近的)保存到硬盘中的.msg存档中。我有这个代码:
Sub prueba(Item As Outlook.MailItem)
Dim oApp As Outlook.Application
Dim oNameSpace As NameSpace
Dim oFolder As MAPIFolder
Dim oMailItem As MailItem
Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.Folders("personal folder").Folders("inbox")
For Each oMailItem In oFolder.Items
MsgBox (oMailItem.Subject)
oMailItem.SaveAs "C:\test\" & oMailItem.Subject & ".msg", olMSG
Next
End Sub
但我的问题在于:
For Each oMailItem In oFolder.Items
因为我只想保存最后一条消息,所以我需要做类似的事情:
set omailitem = ofolder.items.getlast
但是我不能这样做,我需要帮助!
答案 0 :(得分:0)
您需要先对Items集合进行排序:
set Items = ofolder.items
Items.Sort "[ReceivedTime]", false
set Item = Items.GetLast
MsgBox Item.Subject