Excel VBA - 通过 Lync / Communicator 发送群组消息 API

Excel VBA - Sending Group Message via Lync / Communicator API

我正在尝试使用 VBA.

通过 Lync/Microsoft Communicator 从 Excel 向多个用户发送群组消息

下面的代码适用于单个电子邮件 address/user,但如果提供了两个电子邮件地址的单元格范围,则会出现 "Method 'CreateGroup' of Object IMessengerAdvanced' failed" 错误。任何建议将不胜感激。

Sub sendIM()
 Dim msgr As CommunicatorAPI.IMessengerConversationWndAdvanced
 Dim msgTo As Variant
 msgTo = Sheets("Sheet1").Range("A1:A2").Value
 msgr = Messenger.InstantMessage(msgTo)
 msgr.SendText ("Test")
End Sub

根据下面的先前主题,InstantMessage(Object) 方法应该适用于 >1 个用户,但实际上它似乎并不...

Lync notification of offline people using VBA

发送到群组时,界面需要一个 数组 的电子邮件地址。

而不是:

Sub sendIM()
 Dim msgr As CommunicatorAPI.IMessengerConversationWndAdvanced
 Dim msgTo As Variant
 msgTo = Sheets("Sheet1").Range("A1:A2").Value
 msgr = Messenger.InstantMessage(msgTo)
 msgr.SendText ("Test")
End Sub

测试这个:

Sub sendIM()
 Dim msgr As CommunicatorAPI.IMessengerConversationWndAdvanced

 Dim msgTo() As Variant
 ReDim msgTo(0 To 0)                       'Allocate first element
 For Each cell In Sheets("Sheet1").Range("A1:A2")'put your range here
     msgTo(UBound(msgTo)) = cell.Value2          'Assign the array element
     ReDim Preserve msgTo(UBound(msgTo) + 1) 'Allocate next element
 Next
 ReDim Preserve msgTo(LBound(msgTo) To UBound(msgTo) - 1)  'Deallocate the last, unused element

 'sometimes you need to use Set, sometimes you dont, depending on environment you have, or maybe OPTION EXPLICIT
 Set msgr = Messenger.InstantMessage(msgTo)
 'msgr = Messenger.InstantMessage(msgTo)
 msgr.SendText ("Test")
End Sub