You could probably adapt this to other sources, but Google makes it pretty easy.
Try this:
Public Function getGoogDistanceTime(startAddr As String, startCity As String, _
startState As String, startZip As String, endAddr As String, _
endCity As String, endState As String, endZip As String) As String
Dim sURL As String
Dim HTTPreq As Object
Dim BodyTxt As String
Dim s As String, _
d As String, _
t As String
sURL = "http://maps.google.com/maps?f=d&source=s_d&saddr="
sURL = sURL & Replace(startAddr, " ", "+") & ",+" & Replace(startCity, " ", "+") & ",+" & startState
sURL = sURL & "&daddr=" & Replace(endAddr, " ", "+") & ",+" & Replace(endCity, " ", "+") & ",+" & endState
sURL = sURL & "&hl=en"
Set HTTPreq = CreateObject("msxml2.xmlhttp")
With HTTPreq
.Open "get", sURL, False
.send
BodyTxt = .responseText
End With
Set HTTPreq = Nothing
s = "distance:"""
If InStr(1, BodyTxt, s) = 0 Then getGoogDistanceTime = "Error": Exit Function
d = Mid(BodyTxt, InStr(1, BodyTxt, s) + Len(s))
d = Mid(d, 1, InStr(1, d, """") - 1)
s = "time:"""
t = Mid(BodyTxt, InStr(1, BodyTxt, s) + Len(s))
t = Mid(t, 1, InStr(1, t, """") - 1)
getGoogDistanceTime = d & " / " & t
End Function
Cleaned it up a little...
[VBA]Public Function getGoogDistanceTime(startAddr As String, startCity As String, _
startState As String, startZip As String, endAddr As String, _
endCity As String, endState As String, endZip As String) As String
Dim sURL As String
Dim BodyTxt As String
sURL = "http://maps.google.com/maps?f=d&source=s_d&saddr="
sURL = sURL & Replace(startAddr, " ", "+") & ",+" & Replace(startCity, " ", "+") & ",+" & startState
sURL = sURL & "&daddr=" & Replace(endAddr, " ", "+") & ",+" & Replace(endCity, " ", "+") & ",+" & endState
sURL = sURL & "&hl=en"
BodyTxt = getHTML(sURL)
If InStr(1, BodyTxt, "distance:""") = 0 Then getGoogDistanceTime = "Error": Exit Function
getGoogDistanceTime = parseGoog("distance", BodyTxt) & " / " & parseGoog("time", BodyTxt)
End Function
Public Function getHTML(strURL As String) As String
'Returns the HTML code underlying a given URL
Dim oXH As Object
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", strURL, False
.send
getHTML = .responseText
End With
Set oXH = Nothing
End Function
Public Function parseGoog(strSearch As String, strHTML As String) As String
strSearch = strSearch & ":"""
If InStr(1, strHTML, strSearch) = 0 Then parseGoog = "Not Found": Exit Function
parseGoog = Mid(strHTML, InStr(1, strHTML, strSearch) + Len(strSearch))
parseGoog = Mid(parseGoog, 1, InStr(1, parseGoog, """") - 1)
End Function[/VBA]