Vb.Net Code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Sub CreateExcelFromCsvFile(ByVal strFolderPath As String, ByVal strFileName As String)
Dim newFileName As String = "NewExcelFile.xls"
Dim oExcelFile As Object
' Open Excel application object
Try
oExcelFile = GetObject(, "Excel.Application")
Catch
oExcelFile = CreateObject("Excel.Application")
End Try
oExcelFile.Visible = False
oExcelFile.Workbooks.Open(strFolderPath + "\" + strFileName)
' Turn off message box so that we do not get any messages
oExcelFile.DisplayAlerts = False
' Save the file as XLS file
oExcelFile.ActiveWorkbook.SaveAs(Filename:=strFolderPath + "\" + newFileName, FileFormat:=Excel.XlFileFormat.xlExcel5, CreateBackup:=False)
' 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