• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Use a macro to move Sent Items

Slipstick Systems

› Developer › Code Samples › Use a macro to move Sent Items

Last reviewed on November 2, 2021     47 Comments

I hear from a lot of users who don't like how Outlook handles sent items with an IMAP account. In older versions of Outlook, IMAP sent items use the local Sent Items folder. While Outlook 2007 and 2010 can be configured to use the IMAP sent folder, when you use a Send by email command in other applications, the sent item goes into the local data file, ignoring the account configuration. Outlook 2013 uses XLIST from the IMAP server to determine the sent items folder, but if the IMAP server doesn't support XLIST, the sent item might be saved locally. Outlook 2016 and newer handles it better, using the folder the server uses or one named Sent Items.

For Exchange users, Sent Items are stored in the account's mailbox (and have an option use the option to Save sent items with the original, if not in the Inbox). But Shared mailboxes save a copy in the users own Sent Items folder by default, but the shared mailbox may be configured save a copy in the shared mailbox sent folder too.

You can solve this problem by monitoring the Sent Items folder and moving sent messages to the desired folder.

Outlook 2013 users who want to move IMAP messages to a local pst file can use this macro too, however, it will not move the messages immediately. They need to sync down from the IMAP server first.

To use the macros on this page, you need to use the GetFolderPath macro from GetFolderPath.

You'll also need to set macro security to low to test the macro.

Press Alt+F11 to open the VBA editor. Expand Project1 and Microsoft Outlook Objects then double click on ThisOutlookSession. Paste the code into ThisOutlookSession. GetFolderPath can be pasted below this macro or in a new module.

To use this with multiple accounts, copy the IF... End IF block and change the account name and folder path for each account.

The account name and the data file name are usually the same - in Outlook 2010 and newer, both are the email address by default.

You need to use the account name as seen in File, Account Settings (or in the From field if you have multiple accounts) and the data file name (and path to the Sent folder) as seen in the folder list.
Account and file names in Outlook

You can get the path to the sent folder from folder properties. Right click on the sent folder, choose Properties. Select the path from the Location field (without the \\) and the folder name from the name field.
properties dialog

Note: this macro will work with any account type.

These macros start when Outlook starts. To test it without restarting Outlook, click in the Application_Startup macro and click the Run button (or press F5).

Only move Sent mail from one account

This macro checks the sender address and only moves mail sent from that address.

Private WithEvents Items As Outlook.Items
 
Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)

If Item.SendUsingAccount = "alias@domain.com" Then
' Get the GetFolderPath function from http://slipstick.me/getfolderpath  
    Set MovePst = GetFolderPath("data file name\Inbox\Sent")
    Item.Move MovePst
End If

End Sub

 

Move Sent mail from Shared Mailbox

This version of the macro works with Exchange Server shared mailboxes. It can either use the GetfolderPath function or resolve the shared mailbox. The Exchange server needs to be configured to save sent items in the shared mailbox.

Private WithEvents olSentItems As Items
Dim olSent As folder
Dim olInbox As folder
 
Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session

' Uses GetFolderPath Function
'  Set olSentItems = GetFolderPath("Outlook Sales\Sent Items").Items
'  Set olInbox = GetFolderPath("Outlook Sales\Inbox")

' looks up shared mailbox name
  Dim objOwner As Outlook.Recipient
  Set NS = Application.GetNamespace("MAPI")
  Set objOwner = NS.CreateRecipient("olsales")
    objOwner.Resolve
       
 If objOwner.Resolved Then
 ' MsgBox objOwner.Name
 Set olInbox = objNS.GetSharedDefaultFolder(objOwner, olFolderInbox)

' Because using objNS.GetSharedDefaultFolder(objOwner, olFolderSentMail) triggers an error
 Set olSentFolder = olInbox.Parent.Folders("Sent Items") 
 Set olSentItems = olSentFolder.Items
 End If

Set objNS = Nothing
End Sub


Private Sub olSentItems_ItemAdd(ByVal Item As Object)

MsgBox "New Item"
    Item.Move olInbox
End Sub

 

Using Multiple IMAP accounts in Outlook 2013 and newer

Beginning with Outlook 2013, IMAP sent messages are stored in the IMAP account's sent folder and you'll need to watch each sent folder for new items.

Because each account in this example is moving sent items to the same data file, we can set the MovePst as a global variable.

This macro will also work with Exchange accounts and POP accounts that have their own pst files for incoming mail.

Private WithEvents Items As Outlook.Items
Private WithEvents GmailItems As Outlook.Items
Private WithEvents AliasItems As Outlook.Items
Dim MovePst As Outlook.Folder

Private Sub Application_Startup()
'watch default account sent folder
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
 
' Use the GetFolderPath function from http://slipstick.me/getfolderpath  
'watch other sent folders
    Set GmailItems = GetFolderPath("me@gmail.com\[Gmail]\Sent Mail").Items
    Set AliasItems = GetFolderPath("diane@domain.com\Sent Items").Items
    
' set move pst
    Set MovePst = GetFolderPath("Outlook Data File\Sent Items")

End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
    Item.Move MovePst
End Sub

Private Sub GmailItems_ItemAdd(ByVal Item As Object)
    Item.Move MovePst
End Sub

Private Sub AliasItems_ItemAdd(ByVal Item As Object)
    Item.Move MovePst
End Sub

 

Multiple IMAP accounts in Outlook 2010 and older

If you are using multiple accounts, you can use IF statements to selectively move messages. This works with Outlook 2010 and older only, because Sent items are moved into the default pst.

Private WithEvents Items As Outlook.Items
 
Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
' Get the GetFolderPath function from http://slipstick.me/getfolderpath  

If Item.SendUsingAccount = "alias@domain.com" Then
   Set MovePst = GetFolderPath("data file name\Inbox\Sent")

ElseIf Item.SendUsingAccount = "alias@domain1.com" Then
   Set MovePst = GetFolderPath("data file name1\Inbox\Sent")

ElseIf Item.SendUsingAccount = "alias@domain2.com" Then
   Set MovePst = GetFolderPath("data file name2\Inbox\Sent")

Else
 Exit Sub

'    Item.UnRead = False
    Item.Move MovePst
End If

End Sub

You could also use Case statements to set the correct Move path.

 

Move all sent messages

This macro assumes you have only one IMAP account in Outlook (and it's set as default data file) or one or more POP accounts in Outlook using the same data file and want to move the mail sent from all accounts to a different folder.

Outlook 2013 (and newer) users who want to move IMAP messages to a local pst file can use this macro too, however, it may not move the messages immediately. Sent messages need to sync down from the IMAP server first.

Private WithEvents Items As Outlook.Items
 
Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
' You need the GetFolderPath function from http://slipstick.me/getfolderpath  
    Set MovePst = GetFolderPath("data file name\Inbox\Sent")
    Item.UnRead = False
    Item.Move MovePst
End Sub

How to use the macros on this page

First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.

The macros on this page need to go into ThisOutlookSession.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the macro code in ThisOutlookSession:

  1. Expand Project1 and double click on ThisOutlookSession.
  2. Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)

More information as well as screenshots are at How to use the VBA Editor

More Information

Messages Aren't Saved in the Sent Items Folder
Configure and Use IMAP Accounts
Choosing the Folder to Save a Sent Message In

Use a macro to move Sent Items was last modified: November 2nd, 2021 by Diane Poremsky
Post Views: 28

Related Posts:

  • Mark Sent Items as Read After Copying with a Rule
  • Use a VBA macro to monitor a folder in a secondary mailbox for new mes
    Monitor secondary mailbox folder for new messages
  • How to use an ItemAdd Macro
  • Syncing iPhone Sent Messages with Outlook

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Comments

  1. Api says

    February 9, 2022 at 4:27 pm

    Hi
    What is the code for macro to archive sent emails from a specific shared mailbox to the shared sent folder?Now the sent email is archived in the sent personal folder

    Reply
    • Diane Poremsky says

      February 9, 2022 at 9:27 pm

      This part of the shared mailbox code gets the sent folder -

       Set olInbox = objNS.GetSharedDefaultFolder(objOwner, olFolderInbox)
      Set olSentFolder = olInbox.Parent.Folders("Sent Items") 

      Where should it be archived?

      This line moves it to the Inbox -
        Item.Move olInbox

      If you want mail your send from the shared mailbox to go into the shared mailbox sent folder, that can be done using a registry key or the admin can configure exchange to do it.
      Save Sent Items in Shared Mailbox Sent Items folder (slipstick.com)

      Reply
  2. Fabiano Cid says

    June 15, 2021 at 2:28 pm

    Hi
    Dear Diane,

    Can you explain in a short video?

    I need move all messages from IMAP sent folder to a PST outlook 2019 folder every time.

    Reply
  3. Tim says

    April 11, 2021 at 2:07 pm

    Hi, I have multiple POP3 inboxes in Outlook and a single IMAP account. Can you provide the complete VBA code I can use to ensure that any Sent emails from any of the POP3 accounts (wildcard ideally rather than having to specify each account) also get copied/moved to the sent folder of the IMAP account?

    Reply
    • Diane Poremsky says

      November 2, 2021 at 3:11 pm

      A wild card won't work - you need to watch each Sent folder.

      Private WithEvents olSentItemsA As Items
      Private WithEvents olSentItemsB As Items
      Private WithEvents olSentItemsC As Items

      Set olSentItemsA = GetFolderPath("AcctA\Sent Items").Items
      Set olSentItemsB = GetFolderPath("AcctB\Sent Items").Items
      Set olSentItemsC = GetFolderPath("AcctC\Sent Items").Items

      And you need an ItemAdd for each -

      Private Sub olSentItemsA_ItemAdd(ByVal Item As Object)
        Item.Move olInbox
      End Sub

      Private Sub olSentItemsB_ItemAdd(ByVal Item As Object)
        Item.Move olInbox
      End Sub

      Private Sub olSentItemsC_ItemAdd(ByVal Item As Object)
        Item.Move olInbox
      End Sub

      Reply
  4. Tumer says

    January 22, 2020 at 7:50 am

    Dear Diane,
    ı hope you are well, I would like when ı try to modified your code in outlook ,outlook cant find recipient or To . would you help me.

    Private WithEvents Items As Outlook.Items

    Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
    End Sub

    Private Sub Items_ItemAdd(ByVal Item As Object)
    Dim RecipientAddress As Variant

    If RecipientAddress = " John, Smith (Canada) " or " john.smith@example.com"
    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = Outlook.Session.Folders("2020").Folders("sent").Folders("ABC")
    Item.Move MovePst
    'End If

    End Sub

    when I made If statement with recipient / To doesnt check and move correct destionation.

    what is my mistake ?

    best Regards
    Tumer

    Reply
  5. Abhijeet says

    April 28, 2016 at 10:06 pm

    Hi

    I have macro that macro send emails with attachment but 500 emails to send so i can not add those in sent item folder

    from setting i remove this add after sending email to sent item folder

    problem is some emails send without attachments so i want identify which emails sent with & without attachments so please tell me any macro that copy paste emails from sent item folder paste in particular folder (Folder is created on Desktop) & then delete that permanently

    Please help me

    Reply
  6. Meaning says

    April 8, 2016 at 12:54 am

    Please help me! I want save sent item as .msg to disk outlook use IMAP protocol

    Reply
    • Diane Poremsky says

      April 8, 2016 at 11:15 pm

      You want to do this using macros? See https://www.slipstick.com/developer/code-samples/save-selected-message-file/ - there is one for sent messages. If you just want to save one or two now and again, you can drag the message from sent items to the hard drive. or open it and use the same command.

      Reply
  7. Pietro says

    February 19, 2016 at 5:06 pm

    Thanks for the tutorial. I would like to use this script for a slightly different function: I need to save the emails added to the "Sent" folder in a local archive, without removing them from "Sent" folder.
    I tried this:
    Private Sub Items_ItemAdd(ByVal Item As Object)
    If Item.SendUsingAccount = "name.surname@domain.com" Then
    Set MovePst = GetFolderPath("abcd\Fold")
    Dim Copied As Object
    Set Copied= Item.copy
    Copied.Move MovePst
    End If
    End Sub

    But it returns "Run-time error '-2147221233 (8004010f)'"
    Can you help with this? Thank you in advance.

    Reply
  8. Fabio says

    May 16, 2015 at 6:11 am

    I was finding IMAP way too complicated...I decided to go back to all pop accounts but I still would like to try something else. What are your thoughts on Google Apps Sync for Outlook?

    Reply
  9. Fabio says

    May 15, 2015 at 2:53 am

    I'm wondering if this would work for Aliases...I decided to switch from POP3 to IMAP (Google Apps) because I wanted to be able to sync with another computer, but I had 3 other aliases configured as additional email addresses with their own pop/smtp settings....I just disabled the ability to retrieve email and used them for sending purposes. I tried doing that with IMAP, but it seems to create a separate set of folders for each alias...somehow I think this configuration doesn't really work with aliases at least this macro might be able to move between IMAP accounts.

    Reply
    • Diane Poremsky says

      May 16, 2015 at 12:29 am

      The method you tried *should* work, but like you said, imap creates more folders. Setting it up as a pop3 account would work.
      https://www.slipstick.com/outlook/config/how-to-create-a-fake-pop3-account/

      The macro can move the sent mail into the gmail imap folder.

      Reply
  10. Pete says

    April 6, 2015 at 11:27 pm

    Using VBA and Outlook for the first time (2010 Version) I get an error with MovePST variable not defined. I have copied your code verbatim and annotated as necessary.

    Reply
    • Diane Poremsky says

      April 7, 2015 at 7:49 am

      That usually means something was not declared and you are using option explicit. Add this as the first line under
      Private Sub Items_ItemAdd(ByVal Item As Object):

      Dim MovePst as Outlook.folder

      if that errors, use just
      Dim MovePst

      Reply
  11. Gary Wood says

    March 27, 2014 at 8:52 pm

    Many thanks, Diane - this is now working perfectly. Thank you so much for your help - much appreciated.

    Reply
  12. Gary Wood says

    March 20, 2014 at 8:29 am

    Hi Diane, I'm sorry to post again about this, but I was wondering if you've had a chance to look at the code, yet? This is the only code I can find online that comes close to what I need to do, and it would be great if we can get it working with Outlook 2013.

    Reply
    • Diane Poremsky says

      March 27, 2014 at 2:14 am

      I see what the problem is - the code was messed up, it's just checking the accounts, not the message.
      use this for the if -
      If Item.SendUsingAccount = "name1" Then

      Reply
  13. Gary Wood says

    March 13, 2014 at 11:55 am

    OK, no worries - I don't mean to rush you, of course. Thanks again for continuing to try and help with this.

    Reply
  14. Gary Wood says

    March 13, 2014 at 8:54 am

    Hi Diane, Just wondering if you had any more thoughts on this, please? I'm in the process of switching email providers, and am keeping my fingers crossed that we can get this code to work, so I can simplify my setup!

    Reply
    • Diane Poremsky says

      March 13, 2014 at 11:19 am

      I'm trying to get caught up on things here and haven't had a chance to test it thoroughly yet.

      Reply
  15. Gary Wood says

    March 12, 2014 at 2:35 am

    Outlook 2013 32-bit. Thanks for continuing to look at this for me.

    Reply
  16. Gary Wood says

    March 11, 2014 at 5:21 am

    Sorry to post again before you've had a chance to reply, Diane, but I think I know what's happening now - just not how to fix it!

    Of the two accounts I have listed in the code, I tried changing the first one to something that doesn't exist. Then, the message was moved to the Sent Items box listed for the second account.

    So, it seems that instead of the script saying "If the message was sent through "NAME1" move it to "NAME1\Sent", but continue to the next option, if it wasn't", it's actually behaving as "If an account with "NAME1" exists - and regardless of whether the message was sent through it - move the message to "NAME1\Sent".

    Does that make sense, and could it explain what's going on? If so, how can I fix it?!

    Many thanks.

    Reply
    • Diane Poremsky says

      March 11, 2014 at 8:54 am

      That does make sense and if often the reason why If's fail. Doubling up on If's can be a problem to, but usually only if using an OR or a "not if". I'll take a look at the code and test it next.

      Reply
  17. Gary Wood says

    March 11, 2014 at 5:08 am

    Thanks, Diane.

    So, that gave me:

    Private Sub Items_ItemAdd(ByVal Item As Object)
    Dim oAccount As Outlook.Account

    For Each oAccount In Application.Session.Accounts

    'repeat for each account
    If oAccount.DisplayName = "NAME1" Then
    msgbox oAccount.DisplayName
    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("NAME1\Sent")
    Item.UnRead = False
    Item.Move MovePst
    End If

    If oAccount.DisplayName = "NAME2" Then

    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("NAME2\Sent Items")
    Item.UnRead = False
    Item.Move MovePst
    End If

    Next
    End Sub

    Interestingly, what happens now is that regardless of which account I send an email through, the Message Box pops up with the Display Name "Name1", and then the message gets moved to the Sent Items box listed for account "Name2"! So, the If/End doesn't seem to be working...

    Reply
    • Diane Poremsky says

      March 12, 2014 at 1:22 am

      What version of Outlook are you using?

      Reply
  18. Gary Wood says

    March 10, 2014 at 4:35 pm

    In fact, testing this further, it seems that the problem is that the If statement isn't working: the code seems to trigger a move for any sent mail -- regardless of the sending account -- to the specified folder path.

    Any ideas?

    Reply
    • Diane Poremsky says

      March 11, 2014 at 1:00 am

      Add msgbox oAccount.DisplayName right after the if statement and see if it pops up the expected account name.

      Reply
  19. Gary Wood says

    March 10, 2014 at 4:08 pm

    Thanks for this code, Diane.

    However, I'm also having difficulty making this work correctly. I want to set it up for multiple accounts. However, once I add the first account, all mail, regardless of the Display Name of the account I send through, gets moved to the first folder path I list in the code.

    I really need to get this working, so would appreciate any suggestions/help anyone can offer.

    Reply
  20. David says

    June 19, 2013 at 5:17 pm

    I added the .DisplayName, this didn't seem to change anything. When I use just one account, it works fine. When I add the 2nd account, it fails. I tried changing just the 2nd account's loop to item.copy instead of item.move, and it threw this error: 450: Wrong number of arguments or invalid property assignment.

    It's worth noting that this is what causes the failure:
    Condition 1:
    I send 1 message from account A. The failure ("cannot be deleted") is in the loop for account B, even though it shouldn't be affected. Notably, the message does get saved in the SENT box for BOTH account A and account B. I'm hoping this helps debug.
    Condition 2:
    I send 1 message from account B. No failure/error message, BUT the message is NOT saved in either accounts' SENT box.
    Condition 3:
    I comment out account A in the code, so this should only work for account B.
    I send 1 message from account A (nothing should happen). Message gets stored only in the sent folder for account B.
    I send 1 message from account B, no message gets stored in either SENT box.
    Condition 4:
    I comment out account B, uncomment account A.
    I send 1 message from account A, the code works properly.

    hope this helps. I'm not much of a de-bugger....

    Reply
  21. David says

    June 10, 2013 at 10:09 am

    Thanks for this, but I'm having an issue with multiple accounts.

    Outlook 2013 this works great with one account. However, when I add another account, nothing happens when I send from the 2nd account. BUT, when I send from the first account this happens:

    1. the mail gets moved to the Sent boxes of BOTH accounts, and
    2. I get this error popup, even when sending from the first account:

    Mircosoft Visual Basic

    Run-time error '-2147221233 (8004010f)':

    the items were copied instead of moved because the original items cannot be deleted. The operation failed. An object cannot be found.

    When I debug, it's stopped next to the 2nd account line:

    Item.Move MovePst

    Here's my code:

    Private WithEvents Items As Outlook.Items

    Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items

    End Sub

    Private Sub Items_ItemAdd(ByVal Item As Object)
    Dim oAccount As Outlook.Account

    For Each oAccount In Application.Session.Accounts

    'repeat for each account
    If oAccount = "David IMAP" Then

    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("David IMAP\Inbox\Sent")
    Item.UnRead = False
    Item.Move MovePst
    End If

    If oAccount = "HostrupHR" Then

    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("HostrupHR\Inbox\Sent")
    Item.UnRead = False
    Item.Move MovePst
    End If

    Next
    End Sub

    Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
    Dim oFolder As Outlook.Folder
    Dim FoldersArray As Variant
    Dim i As Integer

    On Error GoTo GetFolderPath_Error
    If Left(FolderPath, 2) = "\\" Then
    FolderPath = Right(FolderPath, Len(FolderPath) - 2)
    End If
    'Convert folderpath to array
    FoldersArray = Split(FolderPath, "\")
    Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
    If Not oFolder Is Nothing Then
    For i = 1 To UBound(FoldersArray, 1)
    Dim SubFolders As Outlook.Folders
    Set SubFolders = oFolder.Folders
    Set oFolder = SubFolders.Item(FoldersArray(i))
    If oFolder Is Nothing Then
    Set GetFolderPath = Nothing
    End If
    Next
    End If
    'Return the oFolder
    Set GetFolderPath = oFolder
    Exit Function

    GetFolderPath_Error:
    Set GetFolderPath = Nothing
    Exit Function
    End Function

    I tried changing the code to:
    If oAccount = "David IMAP" Then

    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("David IMAP\Inbox\Sent")
    Item.UnRead = False
    Item.Move MovePst
    ElseIf oAccount = "HostrupHR" Then

    ' Get the GetFolderPath function from http://slipstick.me/getfolderpath
    Set MovePst = GetFolderPath("HostrupHR\Inbox\Sent")
    Item.UnRead = False
    Item.Move MovePst
    End If

    That didn't help. I wonder if it's related to the For Each...

    Reply
    • Diane Poremsky says

      June 16, 2013 at 5:48 pm

      This error: the items were copied instead of moved because the original items cannot be deleted. The operation failed. An object cannot be found. says there is a problem deleting the message. When you move with imap, you copy to a folder and delete it from the other folder. Try changing item.move to item.copy and see if it works.

      It looks like i have a typo in the code - you need to check the display name:
      For Each oAccount In Application.Session.Accounts

      'repeat for each account
      If oAccount.DisplayName = "account name" Then

      For multiple accounts wit would be better to assign the account name to a variable and use that in the code - provided the display name and the data file name is identical. I'll update the code to do that too.

      Reply
  22. Nelson says

    April 4, 2013 at 8:37 am

    For myself I get absolutely no error messages, only that the messages do not move.

    Reply
  23. Nils says

    April 1, 2013 at 6:15 am

    No nothing.

    Reply
  24. Nils says

    March 31, 2013 at 12:26 am

    I've also tried the code with no success. I'm using Windows 8, the german version of Outlook 2013 and Mailaccounts from gmx.de and 1und1.de - if that matters. Would love to see a working workaround for this isse.

    Reply
    • Diane Poremsky says

      March 31, 2013 at 7:35 pm

      Do you get any error messages?

      Reply
  25. Nelson says

    March 21, 2013 at 8:17 am

    Thanks for this but for some reason it still does not work. The emails are still in Sent Items (This computer only). Not sure what else to try.

    Reply
    • Diane Poremsky says

      March 21, 2013 at 11:46 am

      I'll test it. (I might regret not testing the code I gave you the other day. :) )

      Reply
  26. Nelson says

    March 20, 2013 at 10:48 am

    I'm sorry but I can't seem to get this to work in Outlook 2013. The mail in 'Sent Items (This computer only)' don't move to the 'Sent Items' folder I am pointing to. Macro security is disabled and debugging doesn't seem to find an error in the code. Clearly I am doing something wrong and I am a novice with this so any help is appreciated.

    Here is my code:

    Private WithEvents Items As Outlook.Items

    Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderSentMail).Items

    End Sub

    Private Sub Items_ItemAdd(ByVal Item As Object)
    Dim oAccount As Outlook.Account

    For Each oAccount In Application.Session.Accounts

    'repeat for each account
    If oAccount = "PSI Email" Then
    Set MovePst = GetFolderPath("PSI Email\Sent Items")
    Item.UnRead = False
    Item.Move MovePst
    End If

    Next
    End Sub

    Sub Whatever()

    Dim Ns As Outlook.NameSpace
    Set Ns = Application.GetNamespace("MAPI")

    'use the default folder
    Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items

    'do whatever

    End Sub

    Reply
    • Diane Poremsky says

      March 20, 2013 at 11:11 am

      You need the GetFolderPath function.

      Try this:

      Private Sub Application_Startup()
      Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
      End Sub

      Private Sub Items_ItemAdd(ByVal Item As Object)
      Dim oAccount As Outlook.Account

      For Each oAccount In Application.Session.Accounts

      'repeat for each account
      If oAccount = "PSI Email" Then
      Set MovePst = GetFolderPath("PSI EmailSent Items")
      Item.UnRead = False
      Item.Move MovePst
      End If

      Next
      End Sub

      Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
      Dim oFolder As Outlook.Folder
      Dim FoldersArray As Variant
      Dim i As Integer

      On Error GoTo GetFolderPath_Error
      If Left(FolderPath, 2) = "\" Then
      FolderPath = Right(FolderPath, Len(FolderPath) - 2)
      End If
      'Convert folderpath to array
      FoldersArray = Split(FolderPath, "")
      Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
      If Not oFolder Is Nothing Then
      For i = 1 To UBound(FoldersArray, 1)
      Dim SubFolders As Outlook.Folders
      Set SubFolders = oFolder.Folders
      Set oFolder = SubFolders.Item(FoldersArray(i))
      If oFolder Is Nothing Then
      Set GetFolderPath = Nothing
      End If
      Next
      End If
      'Return the oFolder
      Set GetFolderPath = oFolder
      Exit Function

      GetFolderPath_Error:
      Set GetFolderPath = Nothing
      Exit Function
      End Function

      Reply
  27. mville says

    December 15, 2012 at 8:05 am

    There are 6 .pst data files. The default .pst containing the default Sent Items folder for Outlook (created by my original POP3 account which has long been deleted) and one for each of the 5 IMAP accounts.

    With no code, the IMAP sent emails go to the default Sent Items folder in the default .pst and not the Sent Mail folder for each IMAP account, hence this code.

    After adding the code, any sent mail goes to the default Sent Items folder and the code in the Items_ItemAdd event is triggered.

    There are 5 accounts (one for each IMAP account) in Application.Session.Accounts, mail.com being the first.

    The mail is moved, but only to the first IMAP account listed. In this case the mail.com Sent folder. The code is definitely running.

    Reply
  28. mville says

    December 15, 2012 at 3:59 am

    Removed the \\ on the path. Still the same outcome. All sent items go to the first account's sent items folder.

    I have 3 other non-gmail accounts so would like to get this working.

    Reply
    • Diane Poremsky says

      December 15, 2012 at 6:47 am

      Is the first account the default account? I've been working on the premise that 'first account' was the one listed first in the code... but if it's the folder all the sent mail goes to when you don't use code, then the code isn't running. Make sure macro security is set to low and click in the Startup macro and click Run.

      Reply
  29. mville says

    December 14, 2012 at 5:30 pm

    Yes:

    For Each oAccount In Application.Session.Accounts

    If oAccount = "mail.com" Then
    Set MovePst = GetFolderPath("\\mail.com\Sent")
    Item.UnRead = False
    Item.Move MovePst
    End If

    If oAccount = "gmail.com" Then
    Set MovePst = GetFolderPath("\\gmail.com\[Gmail]\Sent Mail")
    Item.UnRead = False
    Item.Move MovePst
    End If

    Next

    This is in Outlook 2007, gmail.com sent mail ends up in the mail.com sent folder.

    Reply
    • Diane Poremsky says

      December 14, 2012 at 8:09 pm

      Don't use \\ on the path - also, gmail accounts shouldn't need this. Gmail saves copies in it's sent folder automatically.

      Reply
  30. mville says

    December 14, 2012 at 1:08 pm

    I tried this with multiple IMAP acoounts but all sent mail ends up in the first email account sent items folder only.

    Reply
    • Diane Poremsky says

      December 14, 2012 at 1:49 pm

      Did you repeat this for each account?

      If oAccount = "second account name" Then
      Set MovePst = GetFolderPath("second-imap-account\Inbox\Sent")
      Item.UnRead = False
      Item.Move MovePst
      End If

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 3

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.