Function GetDistance(adr1 As String, adr2 As String) As Variant
Dim url As String
Dim text As String
Dim xhr As New MSXML2.XMLHTTP60
Dim oRe As New RegExp
Dim oMc As MatchCollection
Dim repText As String
oRe.Pattern = """travelDistance"":(\d+.\d+),"
'On Error Resume Next
Application.StatusBar = "Recherche distance en cours …"
url = "http://dev.virtualearth.net/REST/v1/Routes/driving" & _
"?key=AqfaTCi9xqn5pr_NHoTrpRy8g9x9VnHJqqQcCUTr8xG7kofvzNacQMEAg5GmvLII" & _
"&Waypoint.0=" & URLCode(adr1) & _
"&Waypoint.1=" & URLCode(adr2) & _
"&maxSolutions=1" & _
"&distanceUnit=km" & _
"&routeAttributes=excludeItinerary"
xhr.Open "GET", url, False
xhr.send
text = xhr.responseText
Set oMc = oRe.Execute(text)
If oMc.Count > 0 Then
repText = oMc(0).SubMatches(0)
GetDistance = CDbl(Replace(repText, ".", ","))
Else
GetDistance = "Non trouvé"
End If
Application.StatusBar = "Terminé."
End Function