Option
Explicit
Private
Sub
CommandButtonImport_Click2()
Dim
fd
As
Office.FileDialog
Dim
iZeile
As
Long
, oZiel
As
Range
Dim
sSpArr()
As
String
, sZlArr()
As
String
Dim
iBeginn
As
Integer
Set
fd = Application.FileDialog(msoFileDialogFilePicker)
With
fd
.Filters.Clear
.Title =
"Select a CSV File"
.Filters.Add
"CSV"
,
"*.csv"
, 1
.AllowMultiSelect =
False
Dim
sFile
As
String
If
.Show
Then
sFile = .SelectedItems(1)
End
If
End
With
If
sFile <>
""
Then
Sheets.Add , Sheets(Sheets.Count)
On
Error
Resume
Next
ActiveSheet.Name = Replace(Mid$(sFile, InStrRev(sFile,
"\") + 1), "
.csv
", "
")
On
Error
GoTo
0
Set
oZiel = ActiveSheet.Range(
"A1"
)
sZlArr = Split( _
CreateObject(
"Scripting.FileSystemObject"
) _
.OpenTextFile(sFile).readall, vbCrLf)
sSpArr = Split(sZlArr(0),
";"
)
If
sSpArr(0) =
""
Then
iBeginn = 1
For
iZeile = iBeginn
To
UBound(sZlArr)
sSpArr = Split(sZlArr(iZeile),
";"
)
If
UBound(sSpArr) >= 0
Then
oZiel.Offset(iZeile, 0).Resize(, UBound(sSpArr) + 1) = sSpArr
End
If
Next
iZeile
End
If
End
Sub