Lync notification of offline people using VBA

hari picture hari · Jan 7, 2013 · Viewed 10.9k times · Source

I am having a VBA, Added to my outlook, which sends message over Lync. The Script is as given below.


Sub sendIM(toUsers As Variant, message As String)

    Dim msgr As CommunicatorAPI.IMessengerConversationWndAdvanced

   'Open messenger window and send message!!!!!
    Set msgr = messenger.InstantMessage(toUsers)
    msgr.SendText (message)
    Set msgr = Nothing

It works fine. If there are 10 users, in the toUsers variable, then it sends the message to all as a "Group".

What i want is, if there is a user who is offline, I would like to get some notification that the person is not online. The Messenger displays "Error", saying "Cannot invite "n" people to join the meeting".

Can I get some status, which returns me details of all the users, whom the message was not sent?

Answer

FillsTubs picture FillsTubs · Jan 6, 2014

You're going about this the wrong way... Rather than creating your distribution list and then looking for exceptions, look to see who is online and send the message to just those folks.

The following two functions will return an array of all your Lync contacts with their current status. Use the array to target who gets included in your message.

Function LyncContactsStatus() As Variant

Dim appLync As CommunicatorAPI.Messenger

Dim LyncDirectory As CommunicatorAPI.IMessengerContacts

Dim LyncContact As CommunicatorAPI.IMessengerContact

Dim arrContacts() As Variant

Dim lngLoopCount As Long

    Set appLync = CreateObject("Communicator.UIAutomation")
        appLync.AutoSignin
    Set LyncDirectory = appLync.MyContacts

    ReDim arrContacts(LyncDirectory.Count - 1, 1)

    For lngLoopCount = 0 To LyncDirectory.Count - 1
        Set LyncContact = LyncDirectory.Item(lngLoopCount)
        arrContacts(lngLoopCount, 0) = LyncContact.FriendlyName
        arrContacts(lngLoopCount, 1) = LyncStatus(LyncContact.Status)

    Next lngLoopCount

    LyncContactsStatus = arrContacts

    Set appLync = Nothing

End Function



Function LyncStatus(IntStatus As Integer) As String

    Select Case IntStatus
        Case 1      'MISTATUS_OFFLINE
            LyncStatus = "Offline"
        Case 2      'MISTATUS_ONLINE
            LyncStatus = "Online"
        Case 6      'MISTATUS_INVISIBLE
            LyncStatus = "Invisible"
        Case 10     'MISTATUS_BUSY
            LyncStatus = "Busy"
        Case 14     'MISTATUS_BE_RIGHT_BACK
            LyncStatus = "Be Right Back"
        Case 18     'MISTATUS_IDLE
            LyncStatus = "Idle"
        Case 34     'MISTATUS_AWAY
            LyncStatus = "Away"
        Case 50     'MISTATUS_ON_THE_PHONE
            LyncStatus = "On the Phone"
        Case 66     'MISTATUS_OUT_TO_LUNCH
            LyncStatus = "Out to Lunch"
        Case 82     'MISTATUS_IN_A_MEETING
            LyncStatus = "In a meeting"
        Case 98     'MISTATUS_OUT_OF_OFFICE
            LyncStatus = "Out of office"
        Case 114    'MISTATUS_OUT_OF_OFFICE
            LyncStatus = "Do not disturb"
        Case 130    'MISTATUS_IN_A_CONFERENCE
            LyncStatus = "In a conference"
        Case Else
            LyncStatus = "Unknown"
    End Select
End Function