Hi,
I have seen this code here: Postcode finder in Excel and caculate the distance between two postcodes
I would like to understand how could I add my API key to it.
How could I add my API key on the code below?
Thank you for your help.
I have seen this code here: Postcode finder in Excel and caculate the distance between two postcodes
I would like to understand how could I add my API key to it.
How could I add my API key on the code below?
Thank you for your help.
In cell C2 use this UDF formula
Code:
=G_Distance(A2,B2)
In a new module paste this UDF
Code:
Function G_DISTANCE(Origin As String, Destination As String) As Double
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
G_DISTANCE = 0
On Error GoTo exitRoute
Origin = Replace(Origin, " ", "%20")
Destination = Replace(Destination, " ", "%20")
Set myRequest = New XMLHTTP60
myRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" _
& Origin & "&destination=" & Destination & "&sensor=false", False
myRequest.send
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
If Not distanceNode Is Nothing Then G_DISTANCE = distanceNode.Text / 1000
exitRoute:
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function