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

Moving Deleted Items

Slipstick Systems

› Developer › Code Samples › Moving Deleted Items

Last reviewed on August 22, 2016     20 Comments

Or... using the Delete key to file messages.

Let me go on record as saying I think using the Delete key to file messages is a bad idea. But I know there are a lot of people doing it. A lot less since the introduction of Quick Steps, but still too many use the Delete key as a way to quickly clear out the Inbox.

Create a Quick Step

My recommended method with Outlook 2010 and 2013: create a quick step (and assign it a shortcut) to move stuff you want to keep and only use the Deleted Items folder for stuff you don't need to keep.

Once you get in the habit, Ctrl+Shift+1 can be second nature, although it is a little difficult for smaller hands to manage one-handed. If your mouse or keyboard supports programmable keys you might be able to reprogram a key for the shortcut.

Macro to move Deleted Items

This is for a user who uses the Delete key to file messages but her company cleans up the mailboxes nightly, emptying the Deleted items folder.

The macro moves all mail dropped in the deleted items folder to a folder under the Inbox.

Note: with this macro active, the only way to delete anything is by using Shift+Delete to permanently delete. It could be tweaked to look for messages meeting certain conditions, such as marked complete or assigned a category, and move (or not move) those items.

Private WithEvents Items As Outlook.Items
  
Private Sub Application_Startup()
   Dim NS As Outlook.NameSpace
   Set NS = Application.GetNamespace("MAPI")
   Set Items = NS.GetDefaultFolder(olFolderDeletedItems).Items
   Set NS = Nothing
End Sub
  
Private Sub Items_ItemAdd(ByVal Item As Object)
    If TypeOf Item Is Outlook.MailItem Then
        Set fldMove = Session.GetDefaultFolder(olFolderInbox). _
            Folders("Deleted Stuff")
        Item.Move fldMove
    End If
 End Sub

Move messages using a Toolbar button

Although not as easy as the Del key, you can use a toolbar button to move messages to an archive folder. In versions of Outlook that use the traditional toolbar, you can assign a keyboard shortcut. In ribbonized versions, you can add the macro to the QAT and use Alt+ the number representing its position on the QAT.

This sample moves messages from the Inbox to a subfolder named "completed".

To use this macro, you need the GetCurrentItem function at Work with Open Item or Selected Item

Sub MoveDeleted()
 
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As MailItem
     
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
   
' Get GetCurrentItem function athttp://slipstick.me/e8mio
    Set objItem = GetCurrentItem()
           
    Set objDestFolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("completed")
 
    objItem.Move objDestFolder
               
    Set objDestFolder = Nothing
 
End Sub

How to use the macro

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

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

To use 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.)

Application_Startup macros run when Outlook starts. If you are using an Application_Startup macro you can test the macro without restarting Outlook by clicking in the first line of the Application_Startup macro then clicking the Run button on the toolbar or pressing F8.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

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

Moving Deleted Items was last modified: August 22nd, 2016 by Diane Poremsky

Related Posts:

  • Mark Sent Items as Read After Copying with a Rule
  • Empty Multiple Deleted Items Folders using a Macro
  • Automatically block off time before and after meetings
  • Move Outlook Folders using VBA

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.

Subscribe
Notify of
20 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Shanna (@guest_210565)
March 9, 2018 2:53 pm
#210565

I can not get the first macro to do anything, I did all the steps below that are mentioned. I am a very green VBA user, but have practiced some basic ones and they worked. I am using a subfolder to the inbox, is that the issue?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Shanna
March 10, 2018 10:40 pm
#210580

Do you get any error messages?

This line tells the macro to watch the Deleted items folder for new items:
Set Items = NS.GetDefaultFolder(olFolderDeletedItems).Items

This line tells it to move the deleted items to a subfolder called 'deleted stufff' under the inbox. If your folder is named something else, you'll need to use that name in the macro but otherwise, it sounds like the macro should be working.
Set fldMove = Session.GetDefaultFolder(olFolderInbox).Folders("Deleted Stuff")

it is an auto-start macro and will only run if you rrestart outlook or click Run when the cursor is in the application start macro.

0
0
Reply
Nik (@guest_205421)
March 23, 2017 7:42 am
#205421

I get error in VBA: "Variable not defined" with focus to "fldMove ="
How to declare "fldMove"?
With "Dim fldMove As Outlook.MAPIFolder" it was not possible: Error: '-2147221233 (8004010f)'
Thanks

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Nik
March 23, 2017 11:28 am
#205429

Try just Dim fldMove - or remove option explicit from the top of the module.

Does the folder you are using exist?

0
0
Reply
Nik (@guest_205435)
Reply to  Diane Poremsky
March 23, 2017 1:17 pm
#205435

all free variants are ending with error:

"Dim fldMove As MAPIFolder"
"Dim fldMove As Outlook.MAPIFolder"
"Dim fldMove" end wirh error

The folder (as in example "Deleted Stuff") is existing in IMAP storage and is on the same level as deleted items folder.

Deactivate "Option Explicit" don't help.

Is the code compatible with Outlook 2007?

But here is second problem too:
Here is an IMAP4 account and if I press DEL-Key Outlook 2007 set all selected emails on the server as deleted without to move them to trash folder and my setting is after switching between the folders to deleted them but I wont that all this items are moving to trash folder ("soft deleted") and not to be "hard" deleted. Is it possible to moved deleted items automatically to a specified folder (after "DEL"-Key of course, not via separated macro buttons)?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Nik
March 23, 2017 1:43 pm
#205436

How are you calling the folder? This gets you the folder at the same level as inbox, calendar, deleted:
Set fldMove = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Deleted Stuff")
Remove parent. for a subfolder.

>> I press DEL-Key Outlook 2007 set all selected emails on the server as deleted without to move them to trash folder
This is standard behavior for the older versions of outlook. Items are marked as deleted (and stay 'in place') then are purged when you change folders or initiate a purge. More info: https://www.slipstick.com/outlook/config/configure-and-use-imap-accounts/#deleted

0
0
Reply
Nik (@guest_205458)
Reply to  Diane Poremsky
March 24, 2017 3:06 am
#205458

i wrote above taht I make the folder "Deleted Stuff" in an IMAP storage and thans was wrong. Now is the folder "Deleted Stuff" in the local storage with the default folder "olFolderDeletedItems" where I move the deled items (and on the same level with him) and it work! Still a problem is available on this macro: If a moved the items via "Drag&Drop" from the folder "Deleted Stuff" in to the folder "olFolderDeletedItems" then there is no problem with the processing in VBA and the macro continues to work without to restart Outlook. But if I try to moved the items via DEL-key ("soft deleted") I get error from debugger in VBA and the macro stopped to work and I have each time to restart Outlook (or to refresh "Private Sub Application_Startup()" with F5-key). All items that would be deled within a local storage are moved automatically to this default folder "olFolderDeletedItems". But If I deleted an item within an IMAP storage (it is an IMAP4 account) the items are don’t move to this "olFolderDeletedItems" in local storage that is setting as "default deleted folder" in Outlook. I now about this limitation in Outlook 2007 and as you described… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Nik
March 24, 2017 9:05 am
#205463

>> But if I try to moved the items via DEL-key ("soft deleted") I get error from debugger in VBA and the macro stopped to work and I have each time to restart Outlook
what line does it stop on? It's not watching for deleted items, it's watching for messages moved into the deleted items folder (or whatever folder you identify), and shouldn't be erroring just doing other things.

>> All items that would be deled within a local storage are moved automatically to this default folder "olFolderDeletedItems". But If I deleted an item within an IMAP storage (it is an IMAP4 account) the items are don’t move to this "olFolderDeletedItems" in local storage that is setting as "default deleted folder" in Outlook.
IMAP is funky in that deleted items stay in their folder (usually hidden by a view) so the macro wouldn't work... it can watch imap folders, if you just want to move everything to a specified folder using a toolbar button.

AFAIK, you cannot map the deleted key. If i recall correctly, you can set keyboard shortcuts for buttons in Outlook 2007, so you could add the macro to the toolbar then set a shortcut for it.

0
0
Reply
Bryan Jackson (@guest_201785)
September 22, 2016 12:10 pm
#201785

Any tips on moving other deleted items like olAppointment, olContact, and olReport that experience the odd behavior of creating a new mail item when moved from the Deleted Items folder?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Bryan Jackson
September 23, 2016 12:08 am
#201790

You'd need to use if statements and if you wanted to keep them, move them to calendar or contact folders.
If TypeOf Item Is Outlook.AppointmentItem Then
' move to calendar folder
end if

0
0
Reply
Josh (@guest_197861)
April 14, 2016 1:26 pm
#197861

I am new to macros so I am trying to understand/learn if the Macro to move Deleted Items will do this automatically every time outlook is opened or does it just put a shortcut on the ribbon? I would like to be able to automatically move my deleted items to a folder to share with other office staff.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Josh
April 14, 2016 2:32 pm
#197862

The first macro is an itemadd macro and will run automatically. The second macro is used manually.

0
0
Reply
Josh (@guest_197894)
Reply to  Diane Poremsky
April 15, 2016 12:38 pm
#197894

I pasted the first macro you have above and put it into the VBA module and I cant seem to get it to work. I also created a folder using the same name Deleted Stuff. Is there something else that needs to be changed in the Macro? also highlighted in red is Private WithEvents Items As Outlook.Items

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Josh
April 16, 2016 12:01 am
#197924

Did you put the macros in ThisOutlookSession? If you put it in a module, that's why the line is red.

0
0
Reply
Geoff (@guest_200879)
Reply to  Diane Poremsky
August 18, 2016 7:42 pm
#200879

I have the Move Deleted Items macro code pasted into ThisOutlookSession 'VbaProject.OTM window, but it still won't run. When I press the Run button the Macros window opens with an empty list and the Run button greyed out.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Geoff
August 18, 2016 8:03 pm
#200881

the first macro is an itemadd macro - it goes in ThisOutlookSession. The second macro should be in a new module (it should work in thisoutlooksession, but it's good form to put it in a module). You will need this function to use it https://www.slipstick.com/developer/outlook-vba-work-with-open-item-or-select-item/#getcurrentitem (but that would only prevent it from working - you'd still see the macro.)

Oh... did you change the macro security? If it disabled the macros, they won't show up.

0
0
Reply
Geoff (@guest_200946)
Reply to  Diane Poremsky
August 21, 2016 8:12 pm
#200946

I have it set up as per this screen shot. As you can see, still no macro listed to run.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Geoff
August 22, 2016 7:34 am
#200954

Use the Step In button on the Edit toolbar (or F8) and watch it execute each line. There aren't any on error resume next lines so it shouldn't be skipping any lines.

Where is the folder you are moving messages to? This is a folder at the same level as the inbox:
Set objDestFolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("completed")
https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/ shows how to select other folders.

0
0
Reply
Geoff (@guest_200971)
Reply to  Diane Poremsky
August 22, 2016 7:53 pm
#200971

I restarted my PC for other reasons this morning and now it is working :)
So some sort of restart was required - not sure if it was Outlook or Windows that was required.

Although no macro still shows up in the list when you press the green triangle, the code is working.
I did discover that I had to create the "Trash" (my name choice) folder as a sub-folder of the Inbox. It couldn't be a folder at the same level - I assume because of the path you have created within the code.

Thanks for you help Diane.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Geoff
August 22, 2016 10:15 pm
#200974

I started noticing last winter that Outlook was funky if updates were waiting for a reboot. The first incident was similar to yours - the profile was apparently corrupt. But a new profile failed to. Then i noticed the updates waiting for a reboot. I've seen other errors since them.

Yeah, the path is set in the code - you could change it to use any folder.

Automatic macros or ones used in a rule (or any others with the name in this format: 'sub subname(item as mailitem or something)') aren't visible in the Macro list on the developer tab because you can't run them manually.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 19

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.
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
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

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

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 © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment