显示我刚刚发送的电子邮件

时间:2019-11-05 10:23:08

标签: vba outlook outlook-vba

我正在尝试显示我刚刚发送的电子邮件。这个想法是,当我发送电子邮件,并且该电子邮件出现在Outlook的“已发送”文件夹中时,它将自动打开。

下面的代码创建电子邮件,而不是打开新发送到“已发送”文件夹中的邮件。

Private Sub Application_Startup()
    Dim outlookApp As Outlook.Application
    Dim objectNS As Outlook.NameSpace

    Set outlookApp = Outlook.Application
    Set objectNS = outlookApp.GetNamespace("MAPI")
    Set SentItems = objectNS.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub sentItems_ItemAdd(ByVal Item As Object)

    Dim FirstPos, LastPos As Long
    Dim DirectoryLine As String
    Dim myOlMItem As Outlook.MailItem

    On Error GoTo Handler

    Set Item = CreateObject("Outlook.Application")
    Set objOutlookMsg = Item.CreateItem(olMailItem)
    objOutlookMsg.Display

1 个答案:

答案 0 :(得分:0)

无需创建新项目,使用传递的参数作为参数:

Private Sub Application_Startup()
  Dim outlookApp As Outlook.Application
  Dim objectNS As Outlook.NameSpace

  Set outlookApp = Outlook.Application
  Set objectNS = outlookApp.GetNamespace("MAPI")
  Set SentItems = objectNS.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub sentItems_ItemAdd(ByVal Item As Object)
  Item.Display
End Sub