To set the storage folder for an outgoing Outlook message

Status
Not open for further replies.

mcurtis5484

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
I've used the VBA code to set the storage folder for an outgoing Outlook message in the past with Outlook 2007 - Outlook 2013, but it is not working with Outlook 2016. I can select the folder to save the message to, but the message is always saved to the "Sent" folder.

Is there something in the VBA code that needs to be changed for Outlook 2016.

Thanks,

Mark Curtis
 
I'm using an Exchange ActiveSync account (****@msn.com). Here is the code:


Code:
Option Explicit

Private Sub Application_ItemSend(ByVal Item As Object, _
  Cancel As Boolean)
  
  Dim objNS As NameSpace
  Dim objFolder As MAPIFolder

  On Error Resume Next
  Set objNS = Application.Session

  If Item.Class = olMail Then
  Set objFolder = objNS.PickFolder

  If Not objFolder Is Nothing And _
  IsInDefaultStore(objFolder) And _
  objFolder.DefaultItemType = olMailItem Then
   Set Item.SaveSentMessageFolder = objFolder

  Else

  Set objFolder = _
  objNS.GetDefaultFolder(olFolderSentMail)
  Set Item.SaveSentMessageFolder = objFolder

  End If
  End If

  Set objFolder = Nothing
  Set objNS = Nothing

End Sub


Public Function IsInDefaultStore(objOL As Object) As Boolean

  Dim objApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim objInbox As Outlook.MAPIFolder
  Dim blnBadObject As Boolean

  On Error Resume Next

  Set objApp = objOL.Application

  If Err = 0 Then

  Set objNS = objApp.Session
  Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

  Select Case objOL.Class

  Case olFolder

  If objOL.StoreID = objInbox.StoreID Then
  IsInDefaultStore = True
  Else

  IsInDefaultStore = False
  End If

  Case olAppointment, olContact, olDistributionList, _
olJournal, olMail, olNote, olPost, olTask

  If objOL.Parent.StoreID = objInbox.StoreID Then
      IsInDefaultStore = True
  Else
      IsInDefaultStore = False
  End If

Case Else
  blnBadObject = True
  End Select

  Else
  blnBadObject = True
  End If

  If blnBadObject Then
  MsgBox "This function isn't designed to work " & _
  "with " & TypeName(objOL) & _
  " objects and will return False.", _
  , "IsInDefaultStore"

  IsInDefaultStore = False
  End If

  Set objApp = Nothing
  Set objNS = Nothing
  Set objInbox = Nothing

End Function
 
Last edited by a moderator:
If I hit cancel when selecting a storage folder, Outlook crashes and tries to figure why it crashed, and then restarts.
 
Is the Outlook account type, Exchange ActiveSync, causing the code not to work correctly. At work. I have an Outlook Exchange account type, and the same VBA code works fine...

Thanks for your assistance :)
 
The problem is with EAS - you can't change the folders using EAS as it doesn't allow mail uploads. When the account is moved to office365, then it will work as it will be an exchange account.
 
The problem is with EAS - you can't change the folders using EAS as it doesn't allow mail uploads. When the account is moved to office365, then it will work as it will be an exchange account.
Hi Diane
i'm using outlook 2016 with office 365 i user the VBA code to pop up the folder so i can choose which folder to save email, works fine. the only issue if i hit cancel it crashed , it there a way when the pop up folder appear the have the folder SentItems by default instead of the inbox, because its always the inbox by default , by doing that when it pop up if i don't need to file in different folder i hit just ok and it goes to the default one SentItems and not the inbox . thanks for your help
 
This works here with out error when i click Cancel. The original code posted about crashes when i click cancel - it needs better cancel handling. You can't set a default folder with PickFolder; you'd need to use a custom dialog.

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

  Dim objNS As NameSpace
  Dim objFolder As MAPIFolder

  On Error Resume Next

  Set objNS = Application.Session

  If Item.Class = olMail Then
  Set objFolder = objNS.PickFolder

     If TypeName(objFolder) <> "Nothing" Then
     Set Item.SaveSentMessageFolder = objFolder

  Else

  Set objFolder = objNS.GetDefaultFolder(olFolderSentMail)
  Set Item.SaveSentMessageFolder = objFolder

  End If
  End If

  Set objFolder = Nothing
  Set objNS = Nothing

End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Set calendar default to 'none' (policy) Exchange Server Administration 3
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
D VBA - unable to set rule condition 'on this computer only' Outlook VBA and Custom Forms 5
Witzker Set Cursor & Focus from any field to the body of a user Contact form in OL 2019 Outlook VBA and Custom Forms 1
justicefriends How to set a flag to follow up using VBA - for addressee in TO field Outlook VBA and Custom Forms 11
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
O Cannot expand the folder. The set of folders cannot be opened. You do not have permission to log on. Using Outlook 1
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
bmtjedi Set objApp = Application Not Working in O365-32bit Using Outlook 1
F how do i set a reminder in onenote 2010 Using Outlook 8
glnz How set up new IMAP on Outlook-Office 365 and merge in pst from Outlook 2003 for same two email accounts? Using Outlook 5
ChrisK2 Send email to advertise@slipstick.com fails: "The group advertising isn't set up to receive messages from..." Using Outlook 3
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
J Set Timer/Countdown on Emails? Outlook VBA and Custom Forms 3
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
Victor_50 Set all subfolders to not autoarchive Outlook VBA and Custom Forms 11
Z Script to set account? Using Outlook 0
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
J What is the best EntryID format to set on MS Access table Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Can you set reminder to specific times? Using Outlook 7
CWM030 I do not see a way to set the personal archive folder Exchange Server Administration 2
Witzker Macro to set contact reminder to next day 9:00 Outlook VBA and Custom Forms 45
O Set columns for all (sub)folders Using Outlook 8
S Appointment-Cannot set Categories because ConversationID is not set Outlook VBA and Custom Forms 1
Fozzie Bear Correct Method to set up Outlook.com accounts as Exchange Using Outlook.com accounts in Outlook 7
e_a_g_l_e_p_i How to set fonts for emails in all folders in Outlook Using Outlook 1
F Set (flagged) reminder for next business day Using Outlook 4
L how to set downloaded cached emails Using Outlook 5
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
S set a flag task date as the next weekday Outlook VBA and Custom Forms 4
C Set reminder / appointment by right clicking email Using Outlook 1
Diane Poremsky Set Another Data File as Default When Using an Exchange Account Using Outlook 0
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
L set task reminder date to same as start date (without affecting due date) Using Outlook 0
S how to set user properties to a newly created appointment Outlook VBA and Custom Forms 12
C Outlook VBA to set current account Outlook VBA and Custom Forms 1
Diane Poremsky Add Attachments and Set Email Fields During a Mail Merge Using Outlook 0
O How to set subject line in replies using VBA Outlook VBA and Custom Forms 1
A Custom form not showing when recurrence is set for a meeting Using Outlook 0
M Exchange 2013 On premise set MessageRateLimit for User has no effect. Exchange Server Administration 0
A Block user to send emails to specific set of email ids Using Outlook 1
D Outlook 2007 e-mail header- How to set font & font size in received message headers ? Using Outlook 2
Diane Poremsky Exchange account set-up missing in Outlook 2016 Using Outlook 0
E Meeting reminders are set for the recipient Exchange Server Administration 9
M Help! Can't set up IMAP for gmail Using Outlook 2
P Last Change attribute set after viewing a public folder contact Exchange Server Administration 0
S Multiple Gmail account set up in Outlook 365 Using Outlook 1

Similar threads

Back
Top