简体   繁体   中英

Using VBA in excel, is there a way to save emails to a specific folder in drafts?

I wrote a program to generate emails from a report that is downloaded into excel. Currently it saves to the "drafts" folder in outlook, but I want it to save to another folder within drafts to keep them separate from my regular drafts. This is what I have currently.

With objMail
        .To = rngTo
        .Subject = "Next 2 Weeks Orders"
        .HTMLBody = intro & vbNewLine & po & signiature
        .Save
    End With

What is your code that actually creates objMail ? Are you using Application.CreateItem ? Use MAPIFolder.Items.Add on a specific folder instead of Application.CreateItem . Assuming "My custom subfolder" is a child folder of the Drafts folder:

set folder = objOutlook.Session.GetDefaulFolder(16) 'olfolderDrafts
set folder = folder.Folders("My custom subfolder")
set objMail = folder.Items.Add

There are several ways to create new items in Outlook. If you need to save a new item to a specific folder in Outlook you choices are:

  1. Create a new item using the CreateItem method and then use the MoveTo method to place the item to the target folder.
  2. Use the Items.Add method which places new items to the folder where the Items collection comes from. For example:
nSpace = OutlookApp.GetNamespace("MAPI")
targetFolder = nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
folderItems = targetFolder.Items
mail = folderItems.Add(Outlook.OlItemType.olMailItem)

You can find all these ways described with code samples in the How to create and show a new Outlook mail item programmatically: C#, VB.NET article.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM