[SIZE=1]
Option Explicit
Dim lngColumn As Long
Dim lngRow As Long
Private Sub CommandButton1_Click()
Dim avntTime As Variant
Dim avntTimes As Variant
Dim strCity As String
Dim strCountry As String
Dim strLat As String
Dim strLng As String
Dim strURL1 As String
Dim strURL2 As String
On Error Resume Next
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
Range("A6").CurrentRegion.Clear
strCity = Range("B1").Value
strCountry = Range("B2").Value
With CreateObject("MSXML2.DOMDOCUMENT")
.Async = False
strURL1 = "https://maps.googleapis.com/maps/api/geocode/xml?address=" & Replace(strCity & "," & strCountry, " ", "+")
.Load strURL1
If .SelectSingleNode("//status").Text = "OK" Then
strLat = .SelectSingleNode("//location/lat").Text
strLng = .SelectSingleNode("//location/lng").Text
End If
'http://api.met.no/conditions_service.html
'Do not ask too often. Avoid continuous updating of mobile devices. Applications on mobile devices shall not retrieve new data as long as the application is not in use.
strURL2 = "http://api.met.no/weatherapi/locationforecast/1.9/?lat=" & strLat & ";lon=" & strLng 'am_2017
.Load strURL2
Set avntTimes = .SelectNodes("//time[@from=@to]")
lngRow = 5
For Each avntTime In avntTimes
lngRow = lngRow + 1
lngColumn = 0
Call Parse(avntTime)
Next
End With
Range("A6").CurrentRegion.Columns.AutoFit
Application.Goto Range("A6")
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Private Function Parse(avntParent As Variant)
Dim avntAttribute As Variant
Dim avntChild As Variant
lngColumn = lngColumn + 1
Cells(lngRow, lngColumn).Value = avntParent.BaseName
For Each avntAttribute In avntParent.Attributes
lngColumn = lngColumn + 1
Cells(lngRow, lngColumn).Value = avntAttribute.BaseName
lngColumn = lngColumn + 1
Cells(lngRow, lngColumn).Value = avntAttribute.Text
Next
If avntParent.HasChildNodes() Then
For Each avntChild In avntParent.ChildNodes
Call Parse(avntChild)
Next
End If
End Function[/SIZE]