AW: Text in Spalten per VBA
03.07.2018 14:17:03
Bernd
Servus arek,
nach folgendem Prinzip sollte es funktionieren:
Sub csv()
Dim CSV_Pfad As String
Dim Ausgabe As String
Dim WB As Workbook
Dim strSrcFile$, strTmp$, strDelimit$
Dim intFile%, i&, arrSrc
Application.DisplayAlerts = False
Set WB = Workbooks.Add
CSV_Pfad = Application.GetOpenFilename(FileFilter:="CSV-Dateien(*.csv), *.csv", Title:= " _
CSV-Datei zum einlesen")
If CSV_Pfad = "" Or CSV_Pfad = "Falsch" Then
MsgBox "Bitte eine CSV-Datei auswählen"
Exit Sub
End If
i = 0
strDelimit = "." ' Trennzeichen der CSV-Datensätze
intFile = FreeFile()
Open CSV_Pfad For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strTmp
arrSrc = Split(strTmp, strDelimit)
Cells(i + 1, 1) = arrSrc(0)
Cells(i + 1, 2) = arrSrc(1)
Cells(i + 1, 3) = arrSrc(2)
Cells(i + 1, 4) = arrSrc(3) ' nahezu beliebig erweiterbar...
i = i + 1
Loop
Close
Do
Ausgabe = InputBox("Bitte neuen Dateinamen angeben:", "Ausgabedatei")
Loop While Ausgabe = "" Or Ausgabe = "Falsch"
ChDir "C:\Users\bieberbe\Desktop"
WB.SaveAs Filename:="C:\Users\Username\Desktop\" & Ausgabe & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False ' Desktop-Pfad noch _
anpassen
WB.Close False
Set WB = Nothing
Application.DisplayAlerts = True
End Sub