I would like to convert an .CSV file to a .XLSX.
So far i have this code
Public Sub CreateExcelFromCsvFile(ByVal strFolderPath As String)
Dim oExcelFile As ObjectOpen Excel application object
Try
oExcelFile = GetObject(, "Excel.Application")
Catch
oExcelFile = CreateObject("Excel.Application")
End Try
oExcelFile.Visible = False
oExcelFile.Workbooks.Open(strFolderPath)
' Turn off message box so that we do not get any messages
oExcelFile.DisplayAlerts = False
' Save the file as XLS file
Dim adr As String = ""
For i = 0 To btn_chemin_source.Tag.ToString.Split("\").Count - 2
adr += btn_chemin_source.Tag.ToString.Split("\")(i) & "\"
Next
With oExcelFile.ActiveWorkbook
.SaveAs(Filename:=adr & "RD.xlsx", FileFormat:=Excel.XlFileFormat.xlOpenXMLWorkbook, CreateBackup:=False, Local:=True)
.Close(False)
End With
' Close the workbook
'oExcelFile.ActiveWorkbook.Close(SaveChanges:=False)
' Turn the messages back on
oExcelFile.DisplayAlerts = True
' Quit from Excel
oExcelFile.Quit()
' Kill the variable
oExcelFile = Nothing
End Sub
My problem is that even i searched some clues on google to choose the delimiter in "Panel Control > region" and use local=True in SaveAs method, VB still keep using the comma as the delimiter instead of a semicolon, and so my Excel file is unusable.
Do you have any hints about how to pick a chosen delimiter while saving an CSV to xlsx ? :)
Thank you very much for your time!
oExcelFile.Workbooks.OpenText(Filename:=strFolderPath, Local:=True, Semicolon:=True)
. Maybe don't need both Local & Semicolon but worth a go. See what happens – MacroMarc