CSV Konvertierung
05.02.2023 21:03:45
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 beareitet :-( .. Kann mir jemand helfen?
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