Objektvariable oder With-Blockvariable nicht festg
Flo
ich hab da n kleines VBA Problem. Und zwar hab ich das makro nicht selbst geschrieben. Hab es auf der Arbeit von meinem Vorgänger übernommen und wenn ich es jetzt starten möchte, dann kommt die Fehlermeldung "Objektvariable oder With-Blockvariable nicht festgelegt" !!!
Kann mir da jemand weiterhelfen? Hab selbst noch nie etwas mit VBA etc gemacht....
Hier mal das Makro:
Option Explicit
Private IEApp As Object
Private objRe As Object
Sub Orte()
Dim i As Long, strVonPLZ As String, strBisPLZ As String
With Tabelle2
If Not isPLZ(.Range("A1").Text, strVonPLZ) Then Exit Sub '.Range(" ") ist der Zellname der festen PLZ
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 = x => Zeile
For i = 3 To IIf(Len(.Cells(.Rows.Count, 1)), .Rows.Count, .Cells(.Rows.Count, 1).End(xlUp).Row)
' >>> Spalte PLZ Vergleich >>> Spalte Ausgabe Entfernung
If isPLZ(.Cells(i, 26).Text, strBisPLZ) Then .Cells(i, 24).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).SubMatches(0)
Set objMc = Nothing
Set IEDocument = Nothing
End Function es soll dazu dienen die Entfernungen zwischen Postleitzahlen mit Hilfe von Google Maps zu ermitteln.... so dass am schluss die KM Zahl rauskommt!
Vielen Dank schon mal
Grüße Flo