将上次发送的电子邮件从Outlook 2016复制到内存

时间:2019-09-07 14:23:23

标签: excel vba outlook outlook-2010 outlook-2016

我在Outlook 2010上使用下面的代码时没有任何麻烦,但是在2016 Outlook中,它什么也不做,也没有错误。

sub copylastsenttomem ()
 Dim objSentFolder As Outlook.MAPIFolder
 Dim objSentItem As Outlook.MailItem
Dim outForward As Outlook.MailItem
    Dim objNS As Namespace
Dim objFolder As MAPIFolder


Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderSentMail)

  Set outForward = objFolder.Items(1).Forward
 'Set outForward = objFolder.Items(1)
'outForward.Display

 Dim M As MailItem, Buf As MSForms.DataObject
Set M = outForward


Set Buf = New MSForms.DataObject
Buf.SetText M.body
Buf.PutInClipboard


end sub

1 个答案:

答案 0 :(得分:1)

在代码中,您假定“已发送邮件”文件夹中包含任何项目:

  Set objFolder = objNS.GetDefaultFolder(olFolderSentMail)
  Set outForward = objFolder.Items(1).Forward

确保文件夹中至少包含一项要转发的项目。