我有以下代码可以使用。
我现在需要找到包含该主题行的最新电子邮件并将其打开。
打开电子邮件后,我想将附件保存到桌面并关闭已打开的电子邮件。
i
答案 0 :(得分:0)
我建议从MSDN中的Getting Started with VBA in Outlook 2010文章开始。
使用Items类的Find / FindNext或Restrict方法查找具有特定主题行的电子邮件,而不是遍历每封电子邮件并检查主题行。
Sub DemoFindNext()
Dim myNameSpace As Outlook.NameSpace
Dim tdystart As Date
Dim tdyend As Date
Dim myAppointments As Outlook.Items
Dim currentAppointment As Outlook.AppointmentItem
Set myNameSpace = Application.GetNamespace("MAPI")
tdystart = VBA.Format(Now, "Short Date")
tdyend = VBA.Format(Now + 1, "Short Date")
Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items
Set currentAppointment = myAppointments.Find("[Start] >= """ & tdystart & """ and [Start] <= """ & tdyend & """")
While TypeName(currentAppointment) <> "Nothing"
MsgBox currentAppointment.Subject
Set currentAppointment = myAppointments.FindNext
Wend
End Sub