'====================
'Calcul des distances
'====================
Option Explicit
Public Const DIST = "http://www.distance2villes.com/recherche?source="
Sub Distance()
Dim lg As Integer, i As Integer
Dim Url As String, Txt As String, d, temps
With Sheets("Facturation")
ActiveSheet.Unprotect Password:="123"
lg = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 17 To lg
If Range("B" & i).Value <> "" And Range("B" & i).Value <> 0 Then
Url = DIST & .Range("B" & i).Value & "&destination=" & .Range("C" & i).Value
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", Url, False
.send
Txt = .responseText
End With
.Range("E" & i).Value = Split(Split(Txt, "id=""distanciaRuta"">")(1), "</strong>")(0)
'en nombre
.Range("E" & i).NumberFormat = "##,##"
.Range("E" & i) = Val(Replace(.Range("E" & i), ",", ""))
End If
Next i
ActiveSheet.Protect Password:="123"
End With
MsgBox "Le calcul des KMs est terminé !"
End Sub