|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 lm11132 于 2023-1-29 11:15 编辑
固定文本发送(hello,world):
Sub SendDingTalkMessage()
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", False
http.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
Dim message As String
message = "{ ""msgtype"":""text"", ""text"":{ ""content"":""hello,world""}}"
http.Send message
End Sub
单元格变量文本发送(发送单元格S12的内容):
Sub SendDingTalkMessage()
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", False
http.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
Dim message As String
msg = Range("s12")
message = "{ ""msgtype"":""text"", ""text"": { ""content"":""" & msg & """ } }"
http.send message
End Sub
注意:
1.代码为钉钉群机器人消息
2.代码中"access_token" 替换为你自己的钉钉机器人的 Access Token
3.msessage变量是发送消息的messagge数据,可以根据需要自行修改
4.代码不需要其他引用,Microsoft XML(msxml)和XMLHTTP对象都是操作系统自带。
5.代码为单纯的独立发送代码,如需要条件触发或循环等其他复杂需求请自行添加。
|
-
s12单元格的内容
-
发送效果
|