Using Excel VBA to send Skype messages to Group Chat

TrevorDhien picture TrevorDhien · Oct 23, 2014 · Viewed 10.4k times · Source

I'm trying to use Excel VBA to send Skype messages and I found this code

Sub Test()

Dim aSkype As SKYPE4COMLib.Skype
Set aSkype = New SKYPE4COMLib.Skype
Dim oChat As Chat
Dim skUser As SKYPE4COMLib.User
    Set skUser = aSkype.User("user_name")
    Set oChat = aSkype.CreateChatWith(skUser.Handle)
    oChat.OpenWindow
   oChat.SendMessage "automated message"

End Sub

and it works perfectly fine but only for single contacts.. I also found this code

msg.Chat.SendMessage("your message")

that's supposed to send messages to group contacts but I can't seem to integrate it to the above code.. I found a few links online which hints at it being possible but they're all in C# and not VBA.. Any help on this is very much appreciated..

Answer

Automate This picture Automate This · Oct 23, 2014

You need to define more than one user. One way is by using a collection.

Sub Test()    
  Dim aSkype As SKYPE4COMLib.Skype
  Set aSkype = New SKYPE4COMLib.Skype
  Dim oChat As Chat
  Dim skUser As SKYPE4COMLib.User

  Set oMembers = CreateObject("Skype4COM.UserCollection")
  oMembers.Add(oSkype.User("user_name1"))
  oMembers.Add(oSkype.User("user_name2"))

  Set oChat = oSkype.CreateChatMultiple(oMembers)       
  oChat.OpenWindow
  oChat.Topic = "Group Chat Topic"
  oChat.SendMessage "automated message"     
End Sub

Here is a great resource from Skype with lots of VBA examples. See page 21 for multi-chat.