我很好奇是否可以从访问中启动宏,将上次发送的电子邮件从Outlook保存到本地文件夹?我现在有类似的东西,但它在发送时保存所有电子邮件。请指教。
编辑:现在我在访问时将其传递给vb,但收到错误“未找到方法或数据成员”并突出显示第一行。
Sub SaveLastSentItem()
Dim oApp As Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myFolder As Outlook.Folder
Dim myNewFolder As Outlook.Folder
Dim myItem As Outlook.MailItem
Dim myCopiedItem As Outlook.MailItem
Dim myItems As Object
Dim savePath As String
Set oApp = New Outlook.Application
Set myNameSpace = oApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myFolder.Items
myItems.Sort ("[SentOn]")
Set myItem = myItems.GetLast
savePath = "C:\Users\best buy\Downloads\stackoverfow\Individual Reports\" '## Modify as needed
savePath = savePath & myItem.Subject & Format(myItem.CreationTime, " yyyy-mm-dd-hhNNss")
savePath = savePath & ".oft"
myItem.SaveAs savePath, OlSaveAsType.olMsg
End Sub
答案 0 :(得分:0)
是的,您需要按SentOn日期对“已发送”文件夹中的MailItems
进行排序。然后,您可以使用MailItem.GetLast
设置对上次发送的电子邮件的引用。
Sub SaveLastSentItem()
Dim oApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myNewFolder As Outlook.Folder
Dim myItem As Outlook.MailItem
Dim myCopiedItem As Outlook.MailItem
Dim myItems As Object
Dim savePath As String
Set oApp = New Outlook.Application
Set myNameSpace = oApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myFolder.Items
myItems.Sort ("[SentOn]")
Set myItem = myItems.GetLast
savePath = "C:\Users\best buy\Downloads\stackoverfow\Individual Reports\" '## Modify as needed
savePath = savePath & myItem.Subject & Format(myItem.CreationTime, " yyyy-mm-dd-hhNNss")
savePath = savePath & ".oft"
myItem.SaveAs savePath, OlSaveAsType.olMSG
End Sub