Get Outlook’s Currently Selected Time

I got an email from Dennis, a blind computer user (visually impaired as a bat, as he puts it). He uses a screen reading program that includes a scripting language. This language gives him access to the object models so he can get whatever information he needs.

What he needs to know is which day/time is selected when a user is looking at the calendar. That seems like it would be pretty easy, but you may be surprised. I went through every property and method of the ActiveExplorer object and could get there. Next I thought that I could create a new AppointmentItem and read where it defaulted the Start property. When I created a new AppointmentItem using


It defaulted to the current time, not the selected time. Drat.

Next, I discovered that selecting Actions > New Appointment would create an appointment with the proper Start default. The only problem was that I could find that commandbarcontrol. I looped through every commandbar and every control and simply could not locate it. I know it’s there.

Finally, I went with the old standby: SendKeys. This code produced a message box with the currently selected time. I’m sure it’s fraught with danger, but it’s the best I could do.

Sub GetCurrentDay()

    Dim dtSelected As Date
    Dim i As Long
    If Application.ActiveExplorer.CurrentFolder.DefaultItemType = olAppointmentItem Then
        SendKeys “^+A”
        For i = 1 To 10000: DoEvents: Next i
        dtSelected = Application.ActiveInspector.CurrentItem.Start
        Application.ActiveInspector.Close olDiscard
        MsgBox Format(dtSelected, “mm/dd/yyyy hh:mm”)
    End If
End Sub

By the way, this is still an Excel blog, but this particular piece of code goes in Outlook.

Posted in Uncategorized

4 thoughts on “Get Outlook’s Currently Selected Time

  1. Dennis: Did you read that? Wow! What was that “For I = 1 to 35000? part? I can’t iterate through the commandbars collections? That’s one crazy object model.

  2. Dick,

    Yes, I read it but decided to post it as an amusement to us all. Last time I checked my test-machine was still working with the iteration :)

    Anyway, Rob point You to a more reliable and workable source.

    Kind regards,

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.