Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / Office

Fixing the Time Bar on Outlook 2013 Calendar

5.00/5 (1 vote)
6 Mar 2014CPOL2 min read 43.1K  
Outlook 2013 does not advance the current time in the calendar view; here is a hack fix.

Introduction

In Outlook 2013, there is a blue line that highlights the current time in calendar view. However, if you are on another window, say word or another browser, etc., the time line does not update and if you look over at your 2nd monitor where the calendar is, you will see an incorrect time if you are looking at your calendar. This has been bothering me for a long time and I finally got around to finding / hacking a fix.

See the following article where others had the same problem.

Background

I got the basic premise of the solution/hack from the following article which provides a timer that runs a piece of code every minute in Outlook. The trick was to find some Outlook code that I could insert into the timer function that would update the time bar. As it turns out, the CalendarView.Save method does this. One potential side effect I can think of is if you change your calendar view but did not intend to save that view, it will get saved every minute by this hack.

Using the Code

Insert the following code in the ThisOutlookSession module. You can do this by showing the developer ribbon on the menu. Then selecting the developer ribbon/ Visual Basic on the far left of the ribbon.

In the application section, insert the following code. You can open up 'ThisOutlookSession' which opens up the correct source code file. Make sure the application is selected on the upper left hand drop down box.

VB.NET
Private Sub Application_Quit()
  If TimerID <> 0 Then Call DeactivateTimer 'Turn off timer upon quitting **VERY IMPORTANT**
End Sub

Private Sub Application_Startup()
  MsgBox "Activating the Timer."
  Call ActivateTimer(1) 'Set timer to go off every 1 minute
End Sub

Image 1

Then insert a new module by right clicking on Modules and select Insert/Module. Add the following code in that source file.

VB.NET
Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long 'Need a timer ID to eventually turn off the timer. 
                       'If the timer ID <> 0 then the timer is running

Public Sub ActivateTimer(ByVal nMinutes As Long)
  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes
  If TimerID <> 0 _
  Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer
  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)
  If TimerID = 0 Then
    MsgBox "The timer failed to activate."
  End If
End Sub

Public Sub DeactivateTimer()
Dim lSuccess As Long
  lSuccess = KillTimer(0, TimerID)
  If lSuccess = 0 Then
    MsgBox "The timer failed to deactivate."
  Else
    TimerID = 0
  End If
End Sub

Public Sub TriggerTimer(ByVal hwnd As Long, _
ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)
  'MsgBox "The TriggerTimer function has been automatically called!"
   Dim objView As CalendarView
 Dim o As Explorer
 
 For Each o In Application.Explorers
    If o.CurrentView.ViewType = olCalendarView Then
        Set objView = o.CurrentView
        objView.Save
        
    End If
    
 Next o
End Sub

Points of Interest

Note that this code should update multiple calendars if you have multiple open. I didn't spend a lot of time playing around with the code in TriggerTimer to see if another method would update the time bar. It could be there is a better method to call that doesn't have any side effects.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)