如何在Outlook中保存已发送的邮件

时间:2020-02-25 21:26:44

标签: vba outlook

如何将已发送的信件保存到所选文件夹? Item.SaveSentMessageFolder不起作用。 调试期间没有错误

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)     
     Dim message As String
     Dim header As String
     Dim selectFolderName As String
     Dim selectFolderItem As Outlook.MAPIFolder
     Dim oOutlook As New Outlook.Application
     Dim MyData As DataObject
     Set MyData = New DataObject

     message = "Do you want to save the letter to a folder?"
     header = "Save"

     If MsgBox(message, vbYesNo + vbQuestion, header) = vbYes Then
         SavePopUp.Show
         MyData.GetFromClipboard

        selectFolderName = MyData.GetText(1)
         Set oNameSpace = oOutlook.GetNamespace("MAPI")
         Set selectFolderItem = oNameSpace.Folders(1).Folders.Item("Projects").Folders.Item(selectFolderName)
         Set Item.SaveSentMessageFolder = selectFolderItem
     End If

End Sub

2 个答案:

答案 0 :(得分:1)

这是您要做什么吗?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim Select_Folder As folder

    Dim message As String
        message = "Do you want to save the letter to a folder?"
    Dim header As String
        header = "Save"

    If TypeName(Item) = "MailItem" And Item.DeleteAfterSubmit = False Then

       If MsgBox(message, vbYesNo + vbQuestion, header) = vbYes Then
          'Display dialog box
          Set Select_Folder = Application.Session.PickFolder
          Set Item.SaveSentMessageFolder = Select_Folder
       End If

    End If
End Sub

答案 1 :(得分:0)

首先,请勿对商店索引(1)进行硬编码。按名称访问。
其次,只能将SaveSentMessageFolder设置为邮件所在的同一商店中的文件夹。