ich brauche noch mal Eure Profihilfe! :-)
Ich möchte das bestimmte Spalten aus einer CSV in meiner Excel-Lise verteilt werden. Soweit funktioniert das auch ganz gut, allerdings wenn ich es um einen Öffnen-Dialog erweitern wird geht alles kaputt..
Mit diesem Code funktioniert es:
Sub GetData()
Dim strSrcFile$, strTmp$, strDelimit$
Dim intFile%, i&, arrSrc
strSrcFile = "C:\test.csv"
strDelimit = ";"
intFile = FreeFile()
Open strSrcFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strTmp
arrSrc = Split(strTmp, strDelimit)
Cells(i + 5, 1) = arrSrc(1)
Cells(i + 5, 2) = arrSrc(4)
Cells(i + 5, 4) = arrSrc(4)
Cells(i + 5, 7) = arrSrc(0)
i = i + 1
Loop
Close
End Sub
Wenn ich ihn jetzt um einen Öffnen-Dialog erweitere, dann gibts einen Laufzeitfehler.Sub GetData()
Dim strSrcFile$, strTmp$, strDelimit$
Dim intFile%, i&, arrSrc
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Datei wählen"
.InitialFileName = ""
.Filters.Add "CSV-Dateien", "*.csv", 1
.Filters.Add "Alle Dateien", "*.*", 2
If .Show = -1 Then
strSrcFile = .SelectedItems(1)
End If
End With
If strSrcFile "" Then
Open strSrcFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strTmp
arrSrc = Split(strTmp, strDelimit)
Cells(i + 5, 1) = arrSrc(1)
Cells(i + 5, 2) = arrSrc(4)
Cells(i + 5, 4) = arrSrc(4)
Cells(i + 5, 7) = arrSrc(0)
i = i + 1
Loop
Close
End If
End Sub
Kann mir jemand bei der Lösung helfen? Was mache ich falsch?
Laufzeitfehler: 52
Dateiname oder -nummer falsch
Sry, aber meine VBA-Fähigkeiten sind eher... ja... Ihr wisst schon.Danke und Gruß,
Manu