jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
The following code successfully downloads the image from the URL and saves it to the location specified.
Is there any way I could adapt it to insert it straight into the sheet?
Thanks in advance.
Is there any way I could adapt it to insert it straight into the sheet?
Thanks in advance.
Code:
Sub SavingImagesfinal()
Dim http As New XMLHTTP60, htmldoc As New HTMLDocument
Dim htmlas As Object, htmla As Object, html As Object, item As Object
Dim stream As Object, tempArr As Variant, fileSource As String
Dim pic As String, myPicture As Picture, rng As Range
Dim cl As Range, AspectRatio As Double
With http
.Open "GET", "https://www.tesco.com/groceries/en-GB/products/276054144/", False
.send
htmldoc.body.innerHTML = .responseText
End With
Set htmlas = htmldoc.getElementsByClassName("product-image__container")
For Each htmla In htmlas
Set html = htmla.getElementsByTagName("img")(0)
fileSource = Replace(html.src, "about", "http")
tempArr = Split(html.src, "/")
tempArr = tempArr(UBound(tempArr))
With http
.Open "GET", fileSource, False
.send
End With
Set stream = CreateObject("ADODB.Stream")
With stream
.Open
.Type = 1
.write http.responseBody
.SaveToFile ("C:\Users\jamesco\Desktop\CPPP\" & ".jpg")
.Close
End With
Next htmla
End Sub