none
Can I check the out of office status from another Exchange user using VBA? RRS feed

  • Question

  • Hello,

    I'm not sure that I'm in the right Forum but I think so.

    So now I try to explane my Problem.

    I developed an hollidayplaner in MS-Access for our company. Our employers have to apply for a leave. This is what the programm do automaticly by sending an e-mail to the boss. So now I want to check out if the boss is out of office before I send an e-mail.

    The only thing I found is the code below:

    Sub Check_Out_Of_Office() Dim oNS As Outlook.Namespace Dim oStores As Outlook.Stores Dim oStr As Outlook.Store Dim oPrp As Outlook.PropertyAccessor Set oNS = Outlook.GetNamespace("MAPI") Set oStores = oNS.Stores For Each oStr In oStores If oStr.ExchangeStoreType = olPrimaryExchangeMailbox Then Set oPrp = oStr.PropertyAccessor MsgBox oPrp.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B") End If Next End Sub

    But this function only check my own oof-status. Can anyone tell if it is possible to check the oof-status from another exchange user using VBA?

    Kind regards,

    XPSIT

    Ps.: Sorry for my bad english!

    Monday, November 23, 2015 2:08 PM

Answers

  • Hello,

    You can use the GetFreeBusy method of the ExchangeUser class which allows to obtain a String representing the availability of the ExchangeUser for a period of 30 days from the start date, beginning at midnight of the date specified.  Each character in the String is a value indicating if the user is available (0), and optionally, whether a busy time is marked tentative (1), out of office (3), or other (2). For example:

    Sub GetManagerOpenInterval() 
     Dim oManager As ExchangeUser 
     Dim oCurrentUser As ExchangeUser 
     Dim FreeBusy As String 
     Dim BusySlot As Long 
     Dim DateBusySlot As Date 
     Dim i As Long 
     Const SlotLength = 60 
     'Get ExchangeUser for CurrentUser 
     If Application.Session.CurrentUser.AddressEntry.Type = "EX" Then 
     Set oCurrentUser = _ 
     Application.Session.CurrentUser.AddressEntry.GetExchangeUser 
     'Get Manager 
     Set oManager = oManager.GetExchangeUserManager 
     If oManager Is Nothing Then 
     Exit Sub 
     End If 
     FreeBusy = oManager.GetFreeBusy(Now, SlotLength) 
     For i = 1 To Len(FreeBusy) 
     If CLng(Mid(FreeBusy, i, 1)) = 0 Then 
     'get the number of minutes into the day for free interval 
     BusySlot = (i - 1) * SlotLength 
     'get an actual date/time 
     DateBusySlot = DateAdd("n", BusySlot, Date) 
     'To refine this function, substitute actual 
     'workdays and working hours in date/time comparison 
     If TimeValue(DateBusySlot) >= TimeValue(#8:00:00 AM#) And _ 
     TimeValue(DateBusySlot) <= TimeValue(#5:00:00 PM#) And _ 
     Not (Weekday(DateBusySlot) = vbSaturday Or _ 
     Weekday(DateBusySlot) = vbSunday) Then 
     Debug.Print oManager.name & " first open interval:" & _ 
     vbCrLf & _ 
     Format$(DateBusySlot, "dddd, mmm d yyyy hh:mm AMPM") 
     Exit For 
     End If 
     End If 
     Next 
     End If 
    End Sub 
    

    Monday, November 23, 2015 3:17 PM
  • In theory, you can access the other users' mailbox and read that property. But you need to have appropriate access rights, and OOM does not let you access a delegate mailbox unless it is already in the profile.

    You can EWS and the GetMailTips operation - see https://msdn.microsoft.com/en-us/library/office/dd877060(v=exchg.150).aspx

    If using Redemption is an option, it exposes the RDOMailTips object You can use its OutOfOfficeStartTime and OutOfOfficeEndTime properties.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, November 23, 2015 4:47 PM

All replies

  • Hello,

    You can use the GetFreeBusy method of the ExchangeUser class which allows to obtain a String representing the availability of the ExchangeUser for a period of 30 days from the start date, beginning at midnight of the date specified.  Each character in the String is a value indicating if the user is available (0), and optionally, whether a busy time is marked tentative (1), out of office (3), or other (2). For example:

    Sub GetManagerOpenInterval() 
     Dim oManager As ExchangeUser 
     Dim oCurrentUser As ExchangeUser 
     Dim FreeBusy As String 
     Dim BusySlot As Long 
     Dim DateBusySlot As Date 
     Dim i As Long 
     Const SlotLength = 60 
     'Get ExchangeUser for CurrentUser 
     If Application.Session.CurrentUser.AddressEntry.Type = "EX" Then 
     Set oCurrentUser = _ 
     Application.Session.CurrentUser.AddressEntry.GetExchangeUser 
     'Get Manager 
     Set oManager = oManager.GetExchangeUserManager 
     If oManager Is Nothing Then 
     Exit Sub 
     End If 
     FreeBusy = oManager.GetFreeBusy(Now, SlotLength) 
     For i = 1 To Len(FreeBusy) 
     If CLng(Mid(FreeBusy, i, 1)) = 0 Then 
     'get the number of minutes into the day for free interval 
     BusySlot = (i - 1) * SlotLength 
     'get an actual date/time 
     DateBusySlot = DateAdd("n", BusySlot, Date) 
     'To refine this function, substitute actual 
     'workdays and working hours in date/time comparison 
     If TimeValue(DateBusySlot) >= TimeValue(#8:00:00 AM#) And _ 
     TimeValue(DateBusySlot) <= TimeValue(#5:00:00 PM#) And _ 
     Not (Weekday(DateBusySlot) = vbSaturday Or _ 
     Weekday(DateBusySlot) = vbSunday) Then 
     Debug.Print oManager.name & " first open interval:" & _ 
     vbCrLf & _ 
     Format$(DateBusySlot, "dddd, mmm d yyyy hh:mm AMPM") 
     Exit For 
     End If 
     End If 
     Next 
     End If 
    End Sub 
    

    Monday, November 23, 2015 3:17 PM
  • In theory, you can access the other users' mailbox and read that property. But you need to have appropriate access rights, and OOM does not let you access a delegate mailbox unless it is already in the profile.

    You can EWS and the GetMailTips operation - see https://msdn.microsoft.com/en-us/library/office/dd877060(v=exchg.150).aspx

    If using Redemption is an option, it exposes the RDOMailTips object You can use its OutOfOfficeStartTime and OutOfOfficeEndTime properties.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, November 23, 2015 4:47 PM
  • Free/busy and out-of-office state are not at all related.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, November 23, 2015 4:48 PM