meine VBA Kentnisse sind sehr bescheidem. Ich habe hier auch einen Beitrag gefunden, dieser hat mir aber leider nicht geholfen.
Ich habe einen Api Key, diesen auch eingefügt, aber leider funktioniert es trotzdem nicht.
Vielleicht kann mir jemand hier weiterhelfen.
Vorab vielen Dank!
Hier der Code:
Option Explicit
Function G_DISTANCE(Key As String, Origin As String, Destination As String, Optional Requery As _
_
Boolean) As Double
' Developed by Jamie Bull at oCoCarbon - www.ococarbon.com
' 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
Dim tempFile As String
Dim strTemp As String
Dim nextFileNum As Long
G_DISTANCE = 0
On Error GoTo exitRoute
Origin = CleanQuery(Origin)
Destination = CleanQuery(Destination)
' Check for cached version
tempFile = Environ("temp") & "\" & Origin & "_" & Destination & ".tmpdst"
If (Len(Dir(tempFile)) = 0) Or Requery Then ' query Google
' 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 & Key=(key hier) & "&sensor=false", False
myRequest.Send
Else ' otherwise query the temp file
nextFileNum = FreeFile
Open tempFile For Input As #nextFileNum
Line Input #nextFileNum, strTemp
G_DISTANCE = strTemp / 1000
GoTo exitRoute
End If
' Make the XML readable using 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_DISTANCE = distanceNode.Text / 1000
'Cache the result if not cached
If (Len(Dir(tempFile)) = 0) Then Call CreateFile(tempFile, distanceNode.Text)
End If
exitRoute:
' Tidy up memory
Close #nextFileNum
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function