Hello Thanks for responses.
The following is the code I am using in a macro.What I have been doing for example is I have a list of cities in COLA,and a
second list in COL B.I then place this in COL C
=GetDistance(A1,B1,"Australia")
Now this works well and the distances are automatically entered into COL C,but when I then try to copy and paste values only into COL D the formula immediately starts working again and down the bottom left shows cell calculating.After cells have
calculated again I have the list of distances (values only) in COL D.The problem is that because this has used up twice the requests for distances I go over my limit.(The limit for daily requests is 2400).
Public Function GetDistance(StartCity As String, Destination As String, Country As String) As Long
Const BaseUrl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins={startcity}+{country}&destinations={destination}+{country}&mode=driving&language=en&sensor=false"
Dim odoc As Object
Dim Url As String
Url = Replace(Replace(Replace(BaseUrl, "{startcity}", StartCity), "{destination}", Destination), "{country}", Country)
With CreateObject("MSXML2.DOMDocument")
.async = False
.validateOnParse = False
If .Load(Url) = False Then Exit Function
GetDistance = CLng(Split(Replace(Filter(Split(Replace("~" & .documentElement.XML, "</distance>", "<distance>~"), "<distance>"), "~", False)(0), "<value>", "</value>"), "</value>")(1)) / 1000
.abort
End With
End Function
Sub test()
MsgBox (Format(GetDistance("Perth", "Sydney", "Australia"), "#,###")) & " Km"
End Sub
Bookmarks