0

我正在尝试使用 VBA 从 Excel 通过 Lync/Microsoft Communicator 向多个用户发送组消息。

下面的代码适用于单个电子邮件地址/用户,但如果提供了两个电子邮件地址的单元格范围,它会给出“Object IMessengerAdvanced 的方法'CreateGroup'失败”错误。任何建议将不胜感激。

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 个用户,但实际上它似乎并不...

使用 VBA 的离线人员的 Lync 通知

4

1 回答 1

1

发送到组时,该接口需要一个电子邮件地址数组

代替:

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
于 2016-03-01T14:18:36.547 回答