Automating “Work Offline” in Outlook

This may actually be the solution to your productivity problems.

This isn’t the normal post, but I’ll add a few things to make it sort of seem like it is.

If you don’t care about theory or why this is important, skip to the header “Pre-work.”

If you are already familiar with VBA, skip to the Full Code header, copy the code into your workspace, and then go back and create your triggering tasks as described in “Creating a new task.”

The Why

We get work done when we focus on one thing for an extended period of time. Switching from one thing to another requires time to re-orient and re-focus (“switching cost”). Different people have different switching costs, and certain activities have higher or lower switching costs. (These costs likely change over time as your priorities change.)

Email is usually a constant barrage throughout the day, and if you get notifications when they come in, you generally trigger on those. The triggering initiates a switching cost, even if you then decide to ignore the email.

If you happen to be a people-pleaser, you feel anxiety that you might be letting someone down if the email remains unanswered for any period of time.

The reality is, it can almost always wait. That’s why they used email, not a more direct method of contact. So it is in your best interest to check email infrequently (reduce anxiety and switching costs) and batch responses (do one thing at a time, reduce switching costs).

How to automate email checking on your schedule, using Outlook

There are other programs and methods for doing this, but because Outlook is the most popular email program for most enterprises, having a solution here is the best option.

To that end, (with the help of the internet) I developed a method that helps control this:

  1. Work offline the vast majority of the day, and check emails only occasionally
  2. Have your emails checked during a very short window that you define, and have that checking happen without you thinking about it

The ideal situation is you define a three minute window once each day during which you check emails. You may have an argument for up to four times, but I suggest you try once per day for a week and see if anyone complains. They probably won’t, and you’ll begin to retrain yourself away from the belief that “I have to constantly be available to people.” You don’t

So the solution in Outlook is: having a VBA script in Outlook run at specific times, toggling the “Work Offline” button on and off.

For those of you who don’t know that “Work Offline” is an option, open your Outlook right now and click on the “Send / Receive” tab. You should see something like this:

Send receive work offline

My Work Offline is currently offline, so it is depressed (shaded light blue, with a red X).

If Work Offline toggling manually solves 80% of your email problems, stop right here and just use this.

For a while, I turned this on and off manually, but that was a bit of a hassle, so I stopped.

The real power is in automation only.

So to the fun.

How I use it

I check my email only once per day. This allows me to block a 15-60 minute time after checking my email to respond to all email. I write all my responses and then send them all at once. (Use the “Send all” option to send everything when you are offline.)

Send all.png

And I don’t check it again until tomorrow.

I recognize not everyone has this luxury, but if you chunk your email checking to twice or three times each day, then you will recognize vast improvements in productivity.

I believe most people can do the simple steps it takes to set this up. You don’t have to be comfortable in the code (I’ll tell you what to change), but you need to be willing to try. (Worst case scenario, call your IT guy (whether that’s a sister, son, or hired help) if this doesn’t quite work the way you expect.)

Pre-work

Here’s the basics:

You will need

  • Outlook for Windows
    • Outlook for Mac doesn’t support VBA
  • A few fingers
  • The code below
  • Half a brain

In Outlook, make sure you have access to view VBA. You can test this by pressing Alt+F11. If this doesn’t bring up a window that looks like this, these instructions from Microsoft will solve your problem. (If you still can’t change it, you might not have enough permissions within the OS, which is a question for your IT person.)

Alt F11 VBA Window.png

Your window will be empty, most likely. The important fact is you have something like the highlighted portion.

Now that you can open your VBA editing window, we’re ready for

The scary part–Coding

Actually not quite. We need to do a bit more prep work.

Creating a New Task

Create an Outlook task for going online and offline. Name them “Online” and “Offline.”

(Online when you want to go online (read: “check email”, Offline 3-5 mins later when you go offline (read: “stop checking.”))

Go to the task window (bottom highlight), and “New Task” (top left)

Tasks.png

On the New Task window, title the task appropriately (Online) and tell it what day to start (Today). You will also want this tasks to recur daily, so hit “Recurrence.”

New task.png

The Recurrence window is a bit tricky, so don’t get lost. Click the days of the week you want to go online (this may be more or fewer than what I selected). I strongly recommend no end date, or else you might find your productivity hampered in 6 months.

Recurrence.png

After clicking “OK” you will be returned to the task creation window.

Check reminder and have it remind you at the time you want to go online (11:00 AM below.)

Reminder time.png

Save and close.

You should see your new reminder come up in your Task window.

completed online reminder.png

Repeat the “Creating a New Task” instructions, but name the task “Offline” and have it trigger 3-5 mins after the “Online” task. (This optimizes productivity. You will be online for only a few minutes at a time and can’t get distracted by emails coming in at different times. You want them to all come in at once.)

When you’re finished, you should have an “Offline” task also. (I have two of each (online and offline) for those of you who need to check multiple times per day.)

completed online and offline.png

Mine are set for Online at 11:00 AM and Offline at 11:03 AM.

(If you want to check your email multiple times per day (and be unable to check it the rest of the time) you may create multiple Online-Offline pairs and the code will handle these just fine (as long as they have the same names as the original pair).)

E.g.

  • Online 8:00
    Offline 8:03
  • Online 12:00
    Offline 12:03
  • Online 16:00 (4:00 pm)
    Offline 16:03 (4:03 pm)
  • Etc.

I personally think checking more than three times per day is counter-productive, but you may have personal needs that necessitate more frequent emailing.

Ok. On to

The scary stuff–Coding

(It’s really not that bad, I promise.)

You will need two sections of code for this to work right. (Only one of which will you have to make any changes to.)

  1. Code that runs on Outlook startup and sets you in the correct state (online or offline) based on time. (You will have to make a few small and easy edits to match your online-offline schedule.)
  2. Code that is triggered by the tasks you just finished setting up. You should have to make zero changes to this.

Code section 1:

Dim objNameSpace As Outlook.NameSpace

'Set Online/Offline Status on Outlook Startup
Private Sub Application_Startup()
    Set objNameSpace = Application.GetNamespace("MAPI")
 
    'If now is before 10:30 AM or after 10:35 PM on Outlook startup
                                        'Change the numbers | below | to match your online window
    If Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #10:30:00 AM# _
    Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #10:35:00 AM# _
    Then
       'If Outlook is online
       If objNameSpace.Offline = False Then
          'set it offline
          ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
       End If
    'The below section is commented because it should only be used if you have additional times that you go online.
    '  Delete the single quotes ' on the lines below to remove the programming comment on the lines and adjust as necessary
    
    '                                        'Change the numbers | below | to match your online window
    'ElseIf Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #11:05:00 AM# _
    '    Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #11:07:00 AM# _
    'Then
    '   'If Outlook is online
    '   If objNameSpace.Offline = False Then
    '      'set it offline
    '      ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
    '   End If
    ' 'Stop deleting ' on this line   
    
    
    '''''
    ''  Copy the ElseIf block above here if you have more than 2 online times. (Copy and update times as often as necessary)
    '''''
    
    
    
    
    ''''' End copy space
    
    'If now is during your online window
    Else
 
       'If Outlook is offline
       If objNameSpace.Offline = True Then
          'Set it online
          ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          
       End If
    End If
End Sub

Copy the above code into your VBA editor (Alt+F11 from normal Outlook window to open) in the “ThisOutlookSession” Space.

Copy code into the vba editor.png

You may have to click on the highlighted buttons on the left to see the “ThisOutlookSession” option and then double-click on that to open the code window.

The code window should open blank, and you just paste the code in.

Editing the Code

The only editing you should have to do should be clear.

In Lines 7-9, you will see

                                     'Change the numbers | below | to match your online window
If Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #10:30:00 AM# _
Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #10:35:00 AM# _

Change the first number (#10:30:00 AM#) to be the time you go online, change the second to be the time you go offline.

E.g.

                                     'Change the numbers | below | to match your online window
If Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #01:20:00 PM# _
Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #01:25:00 PM# _

If you want to go online at 1:20 PM and offline at 1:25 PM.

That’s it! That is the only code editing you have to do for checking emails once per day.

If you need to check twice per day

(I reiterate, this should not be your default for practical reasons.)

Lines 17-27 Contain code that is commented (not run by the program) that checks a second window of time and correctly sets Outlook to the right Online/Offline status based on time of day. Uncomment this by deleting the first single quote ( ‘ ) on each line until you get to the “End If” line.

Take this

'The below section is commented because it should only be used if you have additional times that you go online.
' Delete the single quotes ' on the lines below to remove the programming comment on the lines and adjust as necessary
' 'Change the numbers | below | to match your online window
'ElseIf Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #11:05:00 AM# _
' Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #11:07:00 AM# _
'Then
' 'If Outlook is online
' If objNameSpace.Offline = False Then
' 'set it offline
' ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
' End If

And make it look like this

'The below section is commented because it should only be used if you have additional times that you go online.
' Delete the single quotes ' on the lines below to remove the programming comment on the lines and adjust as necessary
                                         'Change the numbers | below | to match your online window
ElseIf Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #11:05:00 AM# _
    Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #11:07:00 AM# _
Then
 'If Outlook is online
 If objNameSpace.Offline = False Then
 'set it offline
 ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
 End If

This will allow a second time window to be checked when Outlook starts.

Not quite done yet

The Second Code Block

This is simply a copy/paste.

Copy the following directly under what you edited.

'Change Online/Offline Status based on your tasks you created in outlook
Private Sub Application_Reminder(ByVal Item As Object)
    Dim objOfflineTask As Outlook.TaskItem
    Dim objOnlineTask As Outlook.TaskItem
 
    Set objNameSpace = Application.GetNamespace("MAPI")
 
    If TypeOf Item Is TaskItem Then
       If Item.Subject = "Offline" Then
          Set objOfflineTask = Item
 
          'If Outlook is online when "Offline" task reminder alerts
          If objNameSpace.Offline = False Then
             'Set Outlook offline
             ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          End If
 
          'Clear the reminder by marking task complete
          objOfflineTask.MarkComplete
 
       ElseIf Item.Subject = "Online" Then
          Set objOnlineTask = Item
 
          'If Outlook is offline when "Online" task reminder alerts
          If objNameSpace.Offline = True Then
             'Set Outlook online
             ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          End If
 
          objOnlineTask.MarkComplete
 
       End If
    End If
End Sub

Once it’s copied in, save (which you should have been doing throughout this process). and close Outlook.

If you did it all correctly, your Outlook should start up in Offline mode (assuming it’s not during your Online window) and then your email should check at the times specified in your tasks.

That’s it.

Full Code

Dim objNameSpace As Outlook.NameSpace

'Set Online/Offline Status on Outlook Startup
Private Sub Application_Startup()
    Set objNameSpace = Application.GetNamespace("MAPI")
 
    'If now is before 10:30 AM or after 10:35 PM on Outlook startup
                                        'Change the numbers | below | to match your online window
    If Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #10:30:00 AM# _
    Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #10:35:00 AM# _
    Then
       'If Outlook is online
       If objNameSpace.Offline = False Then
          'set it offline
          ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
       End If
    'The below section is commented because it should only be used if you have additional times that you go online.
    '  Delete the single quotes ' on the lines below to remove the programming comment on the lines and adjust as necessary
    '                                        'Change the numbers | below | to match your online window
    'ElseIf Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #11:05:00 AM# _
    '    Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #11:07:00 AM# _
    'Then
    '   'If Outlook is online
    '   If objNameSpace.Offline = False Then
    '      'set it offline
    '      ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
    '   End If
       
    
    
    '''''
    ''  Copy the ElseIf block above here if you have more than 2 online times. (Copy and update times as often as necessary)
    '''''
    
    
    
    
    ''''' End copy space
    
    'If now is during your online window
    Else
 
       'If Outlook is offline
       If objNameSpace.Offline = True Then
          'Set it online
          ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          
       End If
    End If
End Sub

'Change Online/Offline Status based on your tasks you created in outlook
Private Sub Application_Reminder(ByVal Item As Object)
    Dim objOfflineTask As Outlook.TaskItem
    Dim objOnlineTask As Outlook.TaskItem
 
    Set objNameSpace = Application.GetNamespace("MAPI")
 
    If TypeOf Item Is TaskItem Then
       If Item.Subject = "Offline" Then
          Set objOfflineTask = Item
 
          'If Outlook is online when "Offline" task reminder alerts
          If objNameSpace.Offline = False Then
             'Set Outlook offline
             ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          End If
 
          'Clear the reminder by marking task complete
          objOfflineTask.MarkComplete
 
       ElseIf Item.Subject = "Online" Then
          Set objOnlineTask = Item
 
          'If Outlook is offline when "Online" task reminder alerts
          If objNameSpace.Offline = True Then
             'Set Outlook online
             ActiveExplorer().CommandBars.ExecuteMso ("ToggleOnline")
          End If
 
          objOnlineTask.MarkComplete
 
       End If
    End If
End Sub

 

Attribution:

Much of what I accomplished is based on the backs of other people (as is every coding project). Shirley Zhang of DataNumen provided the code I build upon, but was missing execution code necessary in recent versions of Outlook.

Warnings:

This may not work for Outlook versions before 2016. But why are you still using that anyway? If you are, Shirley’s code may work for you.