Eu consegui chegar na seguinte programação :
Function G_DISTANCIA(Origin As String, Destination As String)
' Requires a reference to Microsoft XML, v6.0
' Draws on the stackoverflow answer at bit.ly/parseXML
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
G_DISTANCIA = 0
' Check and clean inputs
On Error GoTo exitRoute
Origin = Replace(Origin, " ", "%20")
Destination = Replace(Destination, " ", "%20")
' Read the XML data from the Google Maps API
Set myRequest = New XMLHTTP60
myRequest.Open "GET", " http://maps.googleapis.com/maps/api/directions/xml?origin=" _
& Origin & "&destination=" & Destination & "&sensor=false", False
myRequest.send
' Make the XML readable usign XPath
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
' Get the distance node value
Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
If Not distanceNode Is Nothing Then G_DISTANCIA = (distanceNode.Text / 1000) & " KM"
exitRoute:
' Tidy up
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function
‘---------------------------------------------------------------------------------------------------
Function G_duracao(Origin As String, Destination As String) As Double
' Requires a reference to Microsoft XML, v6.0
' Draws on the stackoverflow answer at bit.ly/parseXML
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
G_duracao = 0
' Check and clean inputs
On Error GoTo exitRoute
Origin = Replace(Origin, " ", "%20")
Destination = Replace(Destination, " ", "%20")
' Read the XML data from the Google Maps API
Set myRequest = New XMLHTTP60
myRequest.Open "GET", " http://maps.googleapis.com/maps/api/directions/xml?origin=" _
& Origin & "&destination=" & Destination & "&sensor=false", False
myRequest.send
' Make the XML readable usign XPath
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
' Get the distance node value
Set distanceNode = myDomDoc.SelectSingleNode("//leg/duration/value")
If Not distanceNode Is Nothing Then G_duracao = distanceNode.Text / 86400
exitRoute:
' Tidy up
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function
-------------------------------------------
Porem, me aparece o erro "Dim myRequest As XMLHTTP60 e eu não posso atualizar o excel da empresa devido a burocracia. Será que você consegue me auxiliar ?
OBS.: Formulas
Para retornar a distancia: “=G_DISTANCIA(A1;A2)”
Para retornar o tempo: “=G_duracao(A1;A2)”
Nas funções acima você poderá utilizar CEP ou o endereço.
Postado : 17/11/2015 5:27 am