I am currently using this code to pull out a 5-day forecast along with some decent snaps for a job. I created it from the video I found, but I am having problems with why the delshape process does not delete the shapes as it should.
If anyone has any recommendations, I would appreciate it and also try to explain what is wrong, if possible. I am trying to learn as much as possible with VBA since I am a new user.
Sub CurrentFiveDayForecast()
Dim WS As Worksheet: Set WS = ActiveSheet
>WS.Range("thedate").Value = ""
WS.Range("hightemp").Value = ""
WS.Range("lowtemp").Value = ""
Dim delshape As Shape
For Each delshape In WS.Shapes
If delshape.Type = msoAutoShape Then delshape.Delete
Next delshape
Dim Req As New XMLHTTP
Req.Open "GET", "http://api.worldweatheronline.com/free/v1/weather.ashx?q=Hong+Kong&format=xml&num_of_days=5&key=APIKEY", False
Req.send
Dim Resp As New DomDocument
Resp.LoadXML Req.responseText
Dim Weather As IXMLDOMNode
Dim i As Integer
Dim wShape As Shape
Dim thiscell As Range
For Each Weather In Resp.getElementsByTagName("weather")
i = i + 1
WS.Range("thedate").Cells(1, i).Value = Weather.SelectNodes("date")(0).Text
WS.Range("hightemp").Cells(1, i).Value = Weather.SelectNodes("tempMaxF")(0).Text
WS.Range("lowtemp").Cells(1, i).Value = Weather.SelectNodes("tempMinF")(0).Text
Set thiscell = WS.Range("weatherpictures").Cells(1, i)
Set wShape = WS.Shapes.AddPicture(Weather.SelectNodes("weatherIconUrl")(0).Text, msoFalse, msoCTrue, thiscell.Left, thiscell.Top, thiscell.Width, thiscell.Height)
Next Weather
End Sub
source
share