Recently, I have been using GMail as my primary e-mail client. It’s simple to use, lightweight, fast and powerful. One feature I particularly like is the Archive button, which lets me clear messages out of my inbox with a single click. Instead of letting e-mails clutter up my inbox just in case I need them again, I can archive them as soon as I’ve read them. Fewer items in my inbox makes it easier to focus and prioritize tasks, which in turn makes me more productive.
In the high-pressure environment at work, where I frequently receive up to a hundred or so e-mails a day, everything I can do to make my life easier helps. Here is how I added an Archive button to Microsoft Outlook:
- Make a new folder in Outlook called Archive.
- Open the macro editor under Tools > Macros > Visual Basic Editor.
- Open ThisOutlookSession under Project1 in the Project Explorer window at the left side of the screen.
- Paste the following code:
Option Explicit Public Sub ArchiveSelectedItems() MoveSelectedItemsToFolder "Archive" End Sub Private Sub MoveSelectedItemsToFolder(FolderName As String) On Error GoTo ErrorHandler Dim Namespace As Outlook.Namespace Set Namespace = Application.GetNamespace("MAPI") Dim Inbox As Outlook.MAPIFolder Set Inbox = Namespace.GetDefaultFolder(olFolderInbox) Dim Folder As Outlook.MAPIFolder Set Folder = Inbox.Folders(FolderName) If Folder Is Nothing Then MsgBox "The '" & FolderName & "' folder doesn't exist!", _ vbOKOnly + vbExclamation, "Invalid Folder" End If Dim Item As Object For Each Item In Application.ActiveExplorer.Selection If Item.UnRead Then Item.UnRead = False Item.Move Folder Next Exit Sub ErrorHandler: MsgBox Error(Err) End Sub - Save and close the editor.
Now the archive macro has been created. Let’s add a button that will trigger it:
- Click on View > Toolbars > Customize, and select the Commands tab.
- Scroll down to the Macros category.
- Drag the Project1.ThisOutlookSession.ArchiveSelected command to a toolbar.
- Right-click on your new button, and rename it to Archive Selected. Set it to display Text Only.
- Click Close.
All done!
November 15th, 2007 | 17 Comments



August 20th, 2008 at 4:45 am
This is so great! I love the Archive feature in GMail, adding this on my outlook will save a lot of time!
Thanks!
October 7th, 2008 at 10:13 pm
I would love to have this function but I get an error
” The operation failed. An object could not be found”
Any clue?
October 29th, 2008 at 11:53 am
I got the same error as Koen..
November 1st, 2008 at 12:40 pm
Hi David, let me paste what I said to Koen.
I’m not sure what could be causing your problem. Are you familiar with
VB at all? You could try stepping through the macro to see where it
breaks:
1. Go to Tools > Macro > Visual Basic Editor. Open up the archive code.
2. Right click on the line that says ‘MoveSelectedItemsToFolder
“Archive”‘ and click Toggle > Breakpoint.
3. Go back to your Inbox and click the ‘Archive’ button. The
breakpoint should light up and you can press F8 to step through the
code line by line until it breaks. Right click on variables (e.g.
Namespace, Inbox, Folder) and click ‘Add Watch’ to see what they are.
Hope this helps.
January 1st, 2009 at 6:30 am
I also got this error. To resolve this I had to ensure that I had a folder named Archive located as a SUB FOLDER of Inbox. Once I corrected this, I had no issues.
Best of Luck.
January 9th, 2009 at 12:26 am
Frikkin perfect! Love the feature in gmail and love your solution for outlook. Thanks!
March 18th, 2009 at 8:05 am
Hm, it’s not actually the same though. The archive in GMail just removes the mails from the inbox, but preserves all of the mail’s tags. If you just have the inbox and the archive, it works of course, but personally, I tag most of my mails in GMail.
But then, tagging and folders are entirely different concepts anyway. I can’t imagine going back to such a limited concept as folders are.
March 18th, 2009 at 8:17 am
The semantics might not be exactly the same, but it achieves the same effect — moving something out of the inbox with one click :)
March 19th, 2009 at 8:55 am
GREAT tip !! – this is helping me cope with Outlook @ work :-)
March 26th, 2009 at 5:06 pm
Koen, David & John. I got this error because my Archive folder was not a subfolder of the Inbox folder (it was up on the same level as my Inbox in the Mailbox level).
If you drag your Archive folder into your Inbox folder, the macro should work perfectly as it is.
March 31st, 2009 at 6:55 am
This is a great tip. I was wondering if there was a way that “Archiving” would move the message from the Inbox, to the Inbox in an Archive folder (.pst file loaded into Outlook)? I think then it would truely be “archiving”. Thanks.
April 15th, 2009 at 6:13 pm
Can this be modified so that it moves the messages to the Gmail folder ‘All Mail’ instead of a local folder?
April 16th, 2009 at 9:32 am
@Aiden: afaik the only way to get an e-mail into Gmail is to send it.
April 16th, 2009 at 11:18 am
No worries, I figured out an archive button already exists in Outlook for Gmail – is’s called the DELETE button! If you delete from your Gmail inbox using an IMAP mail client, the message is removed from the inbox but remains in All Mail, so it is automatically archived.
May 7th, 2009 at 8:27 pm
Has anybody a hint how to use this funciton to move Items into other pst-Files?
thanx
July 12th, 2009 at 12:41 am
Note in Outlook 2007, I had to enable macros:
Tools > Macros > Macro Security > Warnings for all macros > OK and restart outlook
Then, to get rid of the warning each time, I signed my Macro with a self cert (free, easy) using these instructions http://grok.lsu.edu/Article.aspx?articleId=593
July 25th, 2009 at 4:39 am
I would paypal you $5 for this solution.
Thank you for posting this.