Option
Explicit
Sub
main()
Call
CSV2XLSX(
"c:\Test\Test.csv"
)
End
Sub
Sub
CSV2XLSX(
ByVal
sDateiPfad
As
String
)
Dim
iFree
As
Integer
Dim
lngCounter
As
Long
Dim
sFile
As
String
Dim
vLines
As
Variant
Dim
wks
As
Excel.Worksheet:
Set
wks = ActiveSheet
iFree = FreeFile
Open sDateiPfad
For
Binary
As
iFree
sFile = Space$(LOF(iFree))
Get
#iFree, , sFile
Close
vLines = Split(sFile, vbCrLf)
For
lngCounter = LBound(vLines)
To
UBound(vLines)
With
ActiveSheet
.Cells(.Rows.Count, 1).
End
(xlUp).Offset(1).Value = vLines(lngCounter)
End
With
Next
With
wks
.SaveAs Filename:=getPath(sDateiPfad) & getFilename(sDateiPfad), FileFormat:=xlOpenXMLWorkbook
.Cells.Clear
End
With
Kill sDateiPfad
End
Sub
Function
getFilename(
ByVal
sDateiPfad
As
String
)
As
String
getFilename = Split( _
Mid(sDateiPfad, _
Start:=1 + InStrRev(sDateiPfad, "\"), _
Length:=Len(sDateiPfad)), Delimiter:=
"."
)(0)
End
Function
Function
getPath(
ByVal
sDateiPfad
As
String
)
As
String
getPath = Left(sDateiPfad, InStrRev(sDateiPfad, "\"))
End
Function