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
 

mcurtis5484

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
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:

mcurtis5484

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
If I hit cancel when selecting a storage folder, Outlook crashes and tries to figure why it crashed, and then restarts.
 

mcurtis5484

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
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 :)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

Fadi Matni

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
Top