NewInExcelAndVBA
New Member
- Joined
- Nov 12, 2013
- Messages
- 1
Hi,
I'm getting picture data through HTTP GET request (FileData = winHttpReq.ResponseBody). I want to embed the picture in the spreadsheet without saving it first. Currently I'm using the following code, which first saves the picture in the local storage and only then inserts the picture into excel. Please help me figure out how to do the same without storing the picture in the local storage:
I'm getting picture data through HTTP GET request (FileData = winHttpReq.ResponseBody). I want to embed the picture in the spreadsheet without saving it first. Currently I'm using the following code, which first saves the picture in the local storage and only then inserts the picture into excel. Please help me figure out how to do the same without storing the picture in the local storage:
Code:
[COLOR=#00008B][FONT=Consolas]Public[/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]Sub[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Test[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]()[/FONT][/COLOR]
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">[COLOR=#00008B]Dim[/COLOR] FileNum [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Long
[/COLOR][COLOR=#00008B]Dim[/COLOR] myURL [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String
[/COLOR][COLOR=#00008B]Dim[/COLOR] FileData() [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Byte
[/COLOR][COLOR=#00008B]Dim[/COLOR] winHttpReq [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Object
[/COLOR][COLOR=#00008B]
Set[/COLOR] winHttpReq = CreateObject([COLOR=#800000]"WinHttp.WinHttpRequest.5.1"[/COLOR])
myURL = [COLOR=#800000]"..."
[/COLOR]winHttpReq.Open [COLOR=#800000]"GET"[/COLOR], myURL, [COLOR=#800000]False
[/COLOR]winHttpReq.Send
FileData = winHttpReq.ResponseBody
FileNum = FreeFileOpen [COLOR=#800000]"C:\Downloads\map.JPG"[/COLOR] [COLOR=#00008B]For[/COLOR] Binary Access Write [COLOR=#00008B]As[/COLOR] #FileNum
Put #FileNum, [COLOR=#800000]1[/COLOR], FileData
Close #FileNum
InsertPic
[COLOR=#00008B]
End[/COLOR] [COLOR=#00008B]Sub
[/COLOR][COLOR=#00008B]
Sub[/COLOR] InsertPic()
[COLOR=#00008B]
Dim[/COLOR] pic [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR]
[COLOR=#00008B]Dim[/COLOR] myPicture [COLOR=#00008B]As[/COLOR] Picture
pic = [COLOR=#800000]"C:\Downloads\map.JPG"
[/COLOR][COLOR=#00008B]Set[/COLOR] myPicture = ActiveSheet.Pictures.Insert(pic)
[COLOR=#00008B]With[/COLOR] myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Top = ActiveSheet.Cells([COLOR=#800000]33[/COLOR], [COLOR=#800000]10[/COLOR]).Top
.Left = ActiveSheet.Cells([COLOR=#800000]33[/COLOR], [COLOR=#800000]10[/COLOR]).Left
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]With
[/COLOR]</code>[COLOR=#00008B]
End[/COLOR] [COLOR=#00008B]Sub[/COLOR]
Last edited: