Liebes Forum
was fehlt hier? Die routine läuft für eine Datei durch und bei der 2. Datei kommt die Fehlermeldung 91, Objektvariable oder with block variablenicht festgelegt.
Danke für alle Antworten!
On Error GoTo error_routine
Dim xl As Excel.Application
Dim xlWrkBk As Excel.Workbook
Dim xlsht As Excel.Worksheet
Dim selImportFile As String
Dim prev As String
Dim z As Integer
DoCmd.SetWarnings True
fpath = "C:\far\importarchiv\"
z = 1
selImportFile = Dir(fpath & "*--import.xls")
Do While selImportFile <> ""
'open file chosen
Set xl = CreateObject("Excel.Application")
Set xlWrkBk = xl.Workbooks.Open(fpath & selImportFile)
Set xlsht = xlWrkBk.Worksheets(1)
xl.Application.Visible = True
xlsht.Range("L2:L1000").Select
Selection.NumberFormat = "0.00"
xlWrkBk.Close True
xl.Quit
Set xlWrkBk = Nothing
Set xlsht = Nothing
Set xl = Nothing
Kill fpath & selImportFile
selImportFile = Dir()
Loop
exit_sub:
Exit Sub
error_routine:
MsgBox Err.Number & " " & Err.Description
MsgBox "Formatfehler in der Datei europa.txt", vbInformation, "N:\far\import\europa.txt"
Resume exit_sub
End Sub
Hallo,
das fehlt:
xl.Selection.NumberFormat = "0.00"
Außerdem wäre es sinnvoll (performanter), Createobject vor die Do-Schleife zu setzen..