宏以创建电子邮件并将其保存在公用文件夹中

时间:2016-01-19 12:37:22

标签: vba email outlook

我想创建一个电子邮件,而不是发送它,将其保存到文件夹中。

喜欢保存到草稿文件夹,但是我选择了一个文件夹。

我正在创建这样的电子邮件:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("TO")
    objOutlookRecip.Type = olTo

    If DisplayMsg Then
        .Display
    Else
        .Save     
    End If
End With

这会将电子邮件保存在“草稿”文件夹中。是否可以选择其他文件夹?

1 个答案:

答案 0 :(得分:0)

您可以将objOutlookMsg移动到名为的文件夹,例如notDraft。

Sub moveTo_NotDraft_Folder()

    Dim objOutlookMsg As mailItem
    Dim objOutlookRecip As recipient

    Dim oNs As Namespace
    Dim inbox As folder
    Dim targetFolder As folder

    Set oNs = GetNamespace("mapi")
    Set inbox = oNs.GetDefaultFolder(olFolderInbox)
    Set targetFolder = inbox.Folders("notDraft")

    Set objOutlookMsg = CreateItem(olMailItem)

    With objOutlookMsg
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("TO")
        objOutlookRecip.Type = olTo
        .Save
        .Move targetFolder
    End With

    Set ActiveExplorer.CurrentFolder = targetFolder

ExitRoutine:

    Set objOutlookMsg = Nothing
    Set objOutlookRecip = Nothing
    Set oNs = Nothing
    Set inbox = Nothing
    Set targetFolder = Nothing

End Sub