To set the folder location for storing an email after it has been sent in Outlook using VBA, you can use the PR_SENTMAIL_ENTRYID
property. This property allows you to specify the folder where sent messages should be stored.
Here’s a general approach to achieve this:
- Create the email from the template: Use the
CreateItem
method to create a new email item from your template. - Set the
PR_SENTMAIL_ENTRYID
property: You can set this property to the entry identifier of the folder where you want to save the sent email.
Here is a simplified example of how you might implement this in VBA:
Sub CreateAndSendEmail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.Folder
Dim entryID As String
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
' Specify the folder where you want to save the sent email
Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox).Folders("YourFolderName") ' Change to your folder name
entryID = olFolder.EntryID
Set olMail = olApp.CreateItemFromTemplate("C:\Path\To\YourTemplate.oft")
' Set the PR_SENTMAIL_ENTRYID property
olMail.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x0E1F001E", entryID
olMail.Subject = "Your Subject"
olMail.To = "recipient@example.com"
olMail.Send
End Sub
In this example, replace "YourFolderName"
with the name of the folder where you want to store the sent emails, and update the path to your template file accordingly.
This way, when you send the email, it will be saved in the specified folder.
References: