How to Auto Set Outlook Online or Offline Based on Your Working Hours

Some users would like to make Outlook to auto switch between online and offline status based on their working hours. So, in this article, we’ll share a quick method with you.

Actually, setting Outlook online or offline is very easy. To turn Outlook into offline status, you can just switch to “Send/Receive” tab and press the “Work Offline” button. And to back to online status, simply hit this button again. However, some users hope that Outlook can automatically switch to offline status when it’s out of working hours and return to online in working hours. Although Outlook does not provide such a feature, you still can utilize the following VBA code to achieve it.

Auto Set Outlook Online or Offline Based on Your Working Hours

Auto Set Outlook Online or Offline Based on Your Working Hours

  1. At the very outset, start your Outlook application.
  2. Then, after getting access to your Outlook, you should open your Tasks folder.
  3. Next you should create a daily recurring Task item.
  • Click on “New Task” button in the ribbon.
  • Then input “Offline” in the Task subject line.
  • Next click on the “Recurrence” button under “Task” tab.
  • In the popup dialog box, select “Daily” recurrence pattern, enable “No end date” and hit “OK”.Create a daily recurring Task item
  • Next you should enable a Reminder at “5:00 PM”.Enable a Reminder at “5:00 PM”
  • Lastly hit the “Save & Close” button.
  1. Subsequently, you need to create another daily recurring Task called “Online” and enable a reminder at “8:00 AM”, shown as the image below:Create another daily recurring Task called “Online”
  2. After that, in Outlook main window, press “Alt + F11” key buttons.
  3. Next you will get access to Outlook VBA editor, in which you need to find and open the “ThisOutlookSession” project.
  4. Later copy the following VBA code into this project.
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 8:00 AM or after 5:00 PM on Outlook startup
    If Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #8:00:00 AM# Or Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #5:00:00 PM# Then
 
       'If Outlook is online
       If objNameSpace.Offline = False Then
          'set it offline
          ActiveExplorer().CommandBars.FindControl(, 5613).Execute
       End If
 
       'If now is between 8:00 AM and 5:00 PM
    Else
 
       'If Outlook is offline
       If objNameSpace.Offline = True Then
          'Set it online
          ActiveExplorer().CommandBars.FindControl(, 5613).Execute
       End If
    End If
End Sub

'Change Online/Offline Status at Specific Time
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.FindControl(, 5613).Execute
          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.FindControl(, 5613).Execute
          End If
 
          objOnlineTask.MarkComplete
 
       End If
    End If
End Sub

VBA Code - Auto Set Outlook Online or Offline Based on Your Working Hours

  1. Eventually, you can restart Outlook to activate this macro.
  2. From now on, your Outlook will be online in working hours and auto switch to offline status outside working hours.

Your Last Resort in the Event of Outlook Crashes

Although Outlook boasts of multiple features, Outlook still can’t keep away from errors and damage. But do not panic. As long as you make sufficient precautions, you still can protect your Outlook data effectively. For instance, you should back up your PST files regularly since backups will enable you to get back corrupt PST data. Also, keeping a powerful repair tool, like DataNumen Outlook Repair, is also a matter of necessity.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including fix mdf and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.