Inbox Zero, Automation with Outlook VBA

Why Inbox Zero?

Time is limited, and attention is finite

I need to safeguard my time and attention.

Really, the email inbox is just too distracting to be a good task tracker

New emails comes in - what do we do? We click it, open it and read it.

Research has shown that it takes an average of 23 minutes and 15 seconds to get back to a task after being interrupted.

Not just that, with each email we spend energy thinking about the next action - to reply or not to reply, work on the task or not work on the task … etc. Email interrupts the state of deep work to pull my attention to the unimportant over the important work.

To guard my brain from my natural instinct to be distracted, I clear out my email as infrequently as I responsibly can. Each time, intentionally decide what action I’ll take on each email - the 4 D’s: delete, delegate, defer or do.

When I need to defer or do, I store and prioritize it with my task management tool of choice, Todoist. I archive the email once I’ve stored and prioritized it.

Here comes the challenge and what we’re trying to fix today: pulling the email up again in the future takes too long, and Outlook’s search sucks.


Fixing the Outlook Search Box with Outlook VBA

So … we will fix it by not using search and build our own email retrieval system.

Here’s the idea: when we archive the email, we will copy some sort of key or identifier. Then using that key or identifier, we can pull up the email instantaneously in the future. See it in action:

1 - Setup/Turn on Macros in Outlook.

1) Press “Alt” + “F11” to pull up the Visual Basic Editor window.

2) You will need to create a UserForm to allow DataObjects (which we will be using in the script).

3) Then, enable macros by:

  • Go to File > Options, Under “Trust Center” tab click “Trust Center Settings”
  • Under “Macro Settings”, choose “Enable all macros (not recommended; potentially dangerous code can run)”
  • Need more help? Here’s a helpful guide.

2 - Creating the Modules

Right click the left sidebar of your Visual Basic Editor, create a new module.

The first module

  • This module moves the selected email into archive, and copy the key/id into your clipboard.
  • Need to change your email address (variable: mailboxNameString)

'Adds a link to the currently selected message to the clipboard
Sub ArchiveCopySelectedMsgInfo()

Dim objOutlook As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim obDestFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim doClipboard As New DataObject

mailboxNameString = "eric.kahei.chan@gmail.com" 'Enter your email address here!

Set objOutlook = Application
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objSourceFolder = objNameSpace.GetDefaultFolder(olFolderInbox) ' From the inbox

Set obDestFolder = objNameSpace.Folders(mailboxNameString).Folders("Archive") ' To archive folder

' Catch when multiple emails were selected
If Application.ActiveExplorer.Selection.Count <> 1 Then
    MsgBox ("Multiple emails were selected, please select only 1.")
    Exit Sub
End If

Set objMail = Application.ActiveExplorer.Selection.Item(1).Move(obDestFolder) ' Move the email

doClipboard.SetText (objMail.SenderName + " (" + objMail.SenderEmailAddress + "): " + objMail.Subject + vbNewLine + vbNewLine + objMail.EntryID)
doClipboard.PutInClipboard ' Copy the objMail.EntryID and other info into your clipboard

End Sub

The second module

  • Right click left sidebar and create another module.
  • This module retrieves the email by the EntryID
Sub OpenByEntryID()

    Dim App As Outlook.Application
    Dim NS As Outlook.NameSpace
    Dim Msg As Outlook.MailItem
    Dim MsgID As Variant

On Error Resume Next
    Set App = CreateObject("Outlook.Application")
    Set NS = App.GetNamespace("MAPI")
    NS.Logon
    MsgID = InputBox("Enter EntryID")
    Set Msg = NS.GetItemFromID(MsgID)
    Msg.Display

End Sub

3 - Add your macros to the Quick Access Toolbar

Select the dropdown from top left, click “More Commands”.

  • In the menu, change “Choose commands from:” to “Macro”, then use the “Add »” button to add the macros to the Quick Access Toolbar


Closing Thoughts

Inbox zero is just a practice for digital decluttering. The focus should really be how we can do more better. Specifically, it’s to intentionally identify distractions that steals our attention from the important to the unimportant, and eliminating those distractions.

Email mismanagement is just one source of those distractions. As it has been said before:

“Habit is either the best of servants or the worst of masters”
- Nathaniel Emmons

Don’t let your notification habit master you. Manage it before it masters you.


That’s it, enjoy Inbox Zero!


Thoughts, comments?:

Reach out on LinkedIn or email.