' ***********************************************************************
' ***** *****
' ***** CODE PierreP56 : http://tatiak.canalblog.com/ *****
' ***** *****
' ***********************************************************************
' >>>>>>>>>>>> modifié par mapomme
' ***********************************************************************
Public Const DIST = "http://www.distance2villes.com/recherche?source="
Sub Distance()
Dim lg As Integer, i As Integer, j&
Dim Url As String, Txt As String, d, temps
With Sheets("Feuil1")
lg = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lg
Url = DIST & .Range("A" & i).Value & "&destination=" & .Range("B" & i).Value
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", Url, False
.send
Txt = .responseText
End With
.Range("C" & i).Value = Split(Split(Txt, "id=""distanciaRuta"">")(1), "</strong>")(0)
' en nombre
.Range("C" & i).NumberFormat = "#,##0"
.Range("C" & i) = Val(Replace(.Range("C" & i), ",", ""))
''.Range("d" & i).Value = Split(Split(Txt, """tiempo"">")(1), "</")(0)
d = Application.Trim(Split(Split(Txt, """tiempo"">")(1), "</")(0)) & " "
temps = 0
If InStr(d, "d") > 0 Then
temps = Val(d)
d = Mid(Mid(d, InStr(d, "d")), InStr(Mid(d, InStr(d, "d")), " ") + 1)
End If
If InStr(d, "h") > 0 Then
temps = temps + Val(d) / 24
d = Mid(Mid(d, InStr(d, "h")), InStr(Mid(d, InStr(d, "h")), " ") + 1)
End If
If InStr(d, "m") > 0 Then
temps = temps + Val(d) / (60 * 24)
End If
.Range("d" & i).NumberFormat = "[hh]:mm"
.Range("d" & i) = temps
Next i
End With
End Sub