1

I want to copy a range of cells in excel sheet and send it via telegram bot as a picture programmatically using VBA.

Here I copy the range as a picture:

Dim rCopy As Range
Set rCopy = ThisWorkbook.ActiveSheet.Range("A14:C14")
rCopy.copyPicture

This code sends HTTP request to the Telegram API:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<ID>&photo=" & rCopy
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")

But I do not know how to get the file from Clipboard and put it to the request.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • This post should help you. https://stackoverflow.com/questions/10954293/how-to-send-files-via-http-post-with-excel-using-vba – Jenn Jun 30 '19 at 13:12
  • Actually the task should be split into two. First of all you need to get a binary content of the picture (I guess the easiest way is to save the image to a file and get the binary contents of this file). Then send the binary content as payload (put it to `.send` argument), but not as a part of URL, since you are sending POST request. Check [this example](https://stackoverflow.com/a/37446402/2165759). – omegastripes Jul 01 '19 at 06:48

0 Answers0