Morning, and i just want to say thank you in advance.
I am running the VBA code, but when I actually run it and pass it the variables, it gives me a #name? error, and I am not sure why. normally, in my experience that is calling the function wrong, but I have imported the dictionary from the json so i am not exactly sure why. as my function is spelled correctly and I am passing it cells, so those cannot be spelled incorrectly.
Returns the number of seconds it would take to get from one place to another
Function TRAVELTIME(origin, destination, apiKey)
Dim strUrl As String
strUrl = "https://maps.googleapis.com/maps/api/directions/json?origin=" & origin & "&destination=" & destination & "&key=" & apiKey
Set httpReq = CreateObject("MSXML2.XMLHTTP")
With httpReq
.Open "GET", strUrl, False
.Send
End With
Dim response As String
response = httpReq.ResponseText
Dim parsed As Dictionary
Set parsed = JsonConverter.ParseJson(response)
Dim seconds As Integer
Dim leg As Dictionary
For Each leg In parsed("routes")(1)("legs")
seconds = seconds + leg("duration")("value")
Next leg
TRAVELTIME = seconds
End Function