31.01.2015, 21:15
Hallo liebe Excelgemeinde,
stehe mal wieder vor einer Aufgabe und ich benötige wieder eure Hilfe! :)
Folgenden Code habe ich im Internet gefunden, bei Ausführen passiert jedoch nichts!
Was ich vorhabe ist, die Entfernung zwischen der PLZ die in A1 steht und er PLZ die in A2 steht. Die PLZ gebe ich immer per Hand ein und beim Auslösen des Codes soll in B1 die Entfernung in KM ausgegeben werden, und in C1 die Fahrzeit!
Kann mir jemand helfen und den Code meinen Vorhaben anpassen?
Für eure Hilfe danke ich im Voraus
LG aus Nürnberg
Alexandra
stehe mal wieder vor einer Aufgabe und ich benötige wieder eure Hilfe! :)
Folgenden Code habe ich im Internet gefunden, bei Ausführen passiert jedoch nichts!
Code:
Option Explicit
Private IEApp As Object
Private objRe As Object
Sub Orte()
Dim i As Long, strVonPLZ As String, strBisPLZ As String
With Tabelle1
If Not isPLZ(.Range("A1").Text, strVonPLZ) Then Exit Sub
Set IEApp = CreateObject("InternetExplorer.Application")
IEApp.Visible = False
Set objRe = CreateObject("vbscript.regexp")
objRe.Pattern = "^(\d+(?:[\D]\d+)? km . .*Minuten)$"
objRe.MultiLine = True
For i = 2 To IIf(Len(.Cells(.Rows.Count, 1)), .Rows.Count, .Cells(.Rows.Count, 1).End(xlUp).Row)
If isPLZ(.Cells(i, 1).Text, strBisPLZ) Then .Cells(i, 2).Value = Entfernung(strVonPLZ, strBisPLZ)
Next i
Set objRe = Nothing
IEApp.Quit
Set IEApp = Nothing
End With
End Sub
Private Function isPLZ(ByVal strVal As String, ByRef strPLZ As String) As Boolean
strPLZ = Trim(strVal)
isPLZ = strPLZ Like "#####"
End Function
Function Entfernung(ByVal strVonPLZ As String, ByVal strBisPLZ As String) As String
Dim IEDocument As Object
Dim objMc As Object
'IEApp.Navigate "http://maps.google.com/maps?saddr=" & strVonPLZ & "&daddr=" & strBisPLZ & "&hl=de"
IEApp.Navigate "http://maps.google.de/maps?f=d&hl=de&geocode=&saddr=" & strVonPLZ & "&daddr=" & strBisPLZ & "&output=html"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Set IEDocument = IEApp.Document
Set objMc = objRe.Execute(IEDocument.Body.innerText)
If objMc.Count Then Entfernung = objMc(0)
Set objMc = Nothing
Set IEDocument = Nothing
End Function
Was ich vorhabe ist, die Entfernung zwischen der PLZ die in A1 steht und er PLZ die in A2 steht. Die PLZ gebe ich immer per Hand ein und beim Auslösen des Codes soll in B1 die Entfernung in KM ausgegeben werden, und in C1 die Fahrzeit!
Kann mir jemand helfen und den Code meinen Vorhaben anpassen?
Für eure Hilfe danke ich im Voraus
LG aus Nürnberg
Alexandra