MailItem.SaveSentMessageFolder Issues and Outlook Data Files

JValenti

New Member
Joined
Mar 7, 2018
Messages
11
Hello All,

So I have been trying all day to get the .SaveSentMessageFolder functionality to work with absolutely no luck. What I am trying to do is from Excel run a macro that auto-generates a pre-populated email, and then based on the customer name automatically placed that sent email into a respective Outlook Data File folder. I have not even had any luck though trying to get the .SaveSentMessageFolder functionality to work on changing the location of a local folder since I figured I would start there and work my way up to the Outlook Data File folder hierarchy. I have redacted some of the below that would be of no value such as defining some variables, but what I am currently getting is a Run-time error ‘422” Object Required on the Set MailItem.SaveSentMessageFolder = OutDestFolder line.
I also tried using .SaveSentMessageFolder = OutDestFolder and recieved a Run-time error '2147024891 (800070005)' You don't have appropriate permission to perform this operation. If I remove that line entirely the program runs and geenrates an email as planned but it still saves the sent email to the sent folder and has use Default Folder selected under the "Save Sent Item To" selection. Thanks for the help!!


Sub ExampleGenerateSalesEmail()

'Written by Josh Valenti on 10-01-19
'Purpose - Expedite Sales Email Creation


Dim OutDestFolder As Outlook.MAPIFolder
Dim itEmail As Outlook.MailItem
Dim Session As Outlook.Namespace
Dim objMail As Outlook.MailItem
Dim objRecipients As Outlook.Recipients
Dim strSignatureFile As String
Dim objFileSystem As Object
Dim objTextStream As Object
Dim strSignature As String


Application.ScreenUpdating = False

StartCell = ActiveCell.Address

'Skipped Defining of FullName, FirstName, CompanyShortName, FileLocation, VersionVal, stRecipient, StBody


Application.DisplayAlerts = False
Set apOutlook = CreateObject("Outlook.Application")


Set Session = apOutlook.GetNamespace("MAPI")
''''''

apOutlook.Session.Logon

Set itEmail = apOutlook.CreateItem(olMailItem)

If TypeOf Item Is MailItem Then
Set objMail = Item
Set objRecipients = objMail.Recipients
End If

strSignatureFile = "C:\Users\vajo5001\AppData\Roaming\Microsoft\Signatures\SaEM Sign with Opt Out no HC.htm"

'Read the specific signature file
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFileSystem.OpenTextFile(strSignatureFile)
strSignature = objTextStream.ReadAll

With itEmail
.HTMLBody = strSignature
.Display
End With

Signature = itEmail.HTMLBody

StBody = "" & StBody

Set OutDestFolder = Session.GetDefaultFolder(olFolderDeletedItems)


With itEmail
.To = stRecipient
.CC = "example.email@example.com"
.Subject = stSubject
.HTMLBody = StBody & & Signature
.Display
.DeferredDeliveryTime = Date + 1 & " 10:45 AM" ' Deliver After 10:45 AM Next Day
Set MailItem.SaveSentMessageFolder = OutDestFolder
End With

End Sub
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,224,937
Messages
6,181,865
Members
453,068
Latest member
DCD1872

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top