我正在编写一个 Excel 宏,该宏在运行另一个宏后发送结果的屏幕截图
。
截取的屏幕截图以 jpg 图像形式保存在目录 C:\documents\SCREENSHOT 中。
我想使用机器人将 picture1.jpg“C:\documents\SCREENSHOT\picture1.jpg”发送到电报组。
我可以使用以下代码轻松发送短信。
Private Sub telegram_pruebas() 'Solicita un mensaje esta función del mensaje y el ID del chat
Dim objRequest As Object 'Con lo que se crea la solicitud de internet
Dim datos_posteo As String 'Lo que enviará por mensaje
Dim token, ChatID, mensaje As String
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ChatID = -xxxxxxxxxxxx
mensaje = "xxxxxxxx"
datos_posteo = "chat_id=" & ChatID & "&text=" & mensaje 'Se 'Se le muestra al robot que enviar y a que chat
Set objRequest = CreateObject("MSXML2.XMLHTTP") 'Crea un request como archivo XHLM
With objRequest
.Open "POST", "https://api.telegram.org/bot" & token & "/sendMessage?", False 'Aqui esta la dirección del sitio web con el api del robot
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 'No se que sea
.send (datos_posteo) 'La indicación de enviar el texto al chat
End With
End Sub
问题是我找不到发送存储在我的计算机中的图像的方法,我看到了文档,它说有必要使用多部分/表单数据方法,但我不知道如何改变我的子 telegram_pruebas()要使用该方法,我已经看到了溢出堆栈和其他页面中的所有示例,并且我尝试了这样的一些
Private Sub telegram_pruebas_photo() 'Solicita un mensaje esta función del mensaje y el ID del chat
Dim objRequest As Object 'Con lo que se crea la solicitud de internet
Dim datos_posteo As String 'Lo que enviará por mensaje
Dim token, ChatID, photo As String
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ChatID = -xxxxxxxxxxx
photo = "C:\documents\SCREENSHOT\picture1.jpg"
datos_posteo = "chat_id=" & ChatID & "&photo=" & photo 'Se 'Se le muestra al robot que enviar y a que chat
Set objRequest = CreateObject("MSXML2.XMLHTTP") 'Crea un request como archivo XHLM
With objRequest
.Open "POST", "https://api.telegram.org/bot" & token & "/sendPhoto?", False 'Aqui esta la dirección del sitio web con el api del robot
.setRequestHeader "Content-Type", "multipart/form-data" 'No se que sea
.send (datos_posteo) 'La indicación de enviar el texto al chat
response = .responseText
End With
MsgBox response
End Sub
这不起作用,我得到一个空的回复。
有人可以修改我的代码来解决问题,或者至少帮助我理解我的错误..
我尝试过这个页面来尝试理解:
如何使用 Excel VBA 将桌面照片发送到 telegram https://stackoverflow.com/questions/61904082/how-to-send-a-desktop-photo-to-telegram-using-excel-vba
使用VBA将本地存储照片发送到Telegram https://stackoverflow.com/questions/67412694/sending-local-storage-photo-into-telegram-with-vba
在电报机器人上发送本地托管的照片 https://stackoverflow.com/questions/53765822/sending-locally-hosted-photo-on-telegram-bot
将照片发送到 Telegram(API / Bot) https://stackoverflow.com/questions/50655555/sending-photo-to-telegram-api-bot
还有很多其他人。
Thanks