4

我有一个 VBA,添加到我的 Outlook 中,它通过 Lync 发送消息。脚本如下所示。


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

它工作正常。如果有 10 个用户,在 toUsers 变量中,它会将消息作为“组”发送给所有人。

我想要的是,如果有一个用户离线,我想收到一些通知,说明这个人不在线。Messenger 显示“错误”,提示“无法邀请“n”个人加入会议”。

我可以获得一些状态,它会返回所有未发送消息的用户的详细信息吗?

4

1 回答 1

5

您这样做是错误的……与其创建您的分发列表然后查找例外情况,不如查看谁在线并将消息仅发送给这些人。

以下两个函数将返回所有 Lync 联系人及其当前状态的数组。使用数组来定位哪些人会包含在您的消息中。

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
于 2014-01-06T17:34:59.013 回答