CSV Konvertierung
06.02.2023 10:20:51
Christian
ich möchte eine CSV Datei als xls konvertieren, dabei sollen Spalten mit Komma getrennt werden. Allerdings sind auch Kommas im Textfeld die durch Ausführungszeichen
gekennzeichnet sind, mit dem unten stehenden Code wird jedoch nur die erste Zeile bearbeitet :-( .. Kann mir jemand helfen?
Wenn ich die Ausrufezeichen im Vorfeld in der CSV entferne, werden die Zeilen bearbeitet, dann hab ich aber das Problem, auch die Kommas im Text wie z.B.
"Herr Veit, Bernhardt" werden bearbeitet. Denn es gibt auch im Textfeld die Variante ohne Vornahmen "Herr Weil". Und schon hab ich das Problem :-(
Im Vorfeld bereits besten Dank
Sub ConvertCSVtoXLS_TEST()
Dim wb As Workbook
Dim ws As Worksheet
Dim strFile As String
Dim strPath As String
Dim strSheet As String
Dim i As Long
Dim LastRow As Long
'Set the file path and name
strPath = "C:\Users\cwinzenburg\Desktop\Belegungsplan\"
strFile = "export.csv"
strSheet = "export"
'Open the CSV file and save as XLS
Set wb = Workbooks.Open(strPath & strFile)
wb.SaveAs strPath & "Belegungsplan.xls", xlWorkbookNormal
wb.Close
'Open the newly saved XLS file
Set wb = Workbooks.Open(strPath & "Belegungsplan.xls")
Set ws = wb.Sheets(strSheet)
'Find the last row in the sheet
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'Loop through each row and format the data
For i = 1 To LastRow
ws.Range("A" & i).NumberFormat = "@"
Next i
'Auto-fit the columns
ws.Columns.AutoFit
'Save and close the XLS file
wb.Save
wb.Close
End Sub
Anzeige