We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.
Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants
Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file.Once the destination file is created, we can delete the source file as shown below. In case of any issue in understanding the code, please add in comment section
Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel")
Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion)
on error resume next
Set objExcel = CreateObject("Excel.application")
set objExcelBook = objExcel.Workbooks.Open(strSrcFile)
objExcel.application.visible=false
objExcel.application.displayalerts=false
If(Conversion = "ExceltoCSV") Then
objExcelBook.SaveAs strDestFile, 23
else
objExcel.ActiveWorkbook.SaveAs strDestFile,-4143
End If
objExcel.Application.Quit
objExcel.Quit
Set objExcel = Nothing
set objExcelBook = Nothing
Set objFSO = CreateObject("scripting.FileSystemObject")
objFSO.DeleteFile(strSrcFile)
Set objFSO =nothing
End Function
ReplyDeleteExcel is a software program from Microsoft basic excel for beginners that is a part of Microsoft Office. Excel calculations is compiled for making and altering spreadsheets that are spared with a .xls expansion. It's general uses in corporate cell-based figuring, turn tables, and different diagramming devices. With an Excel spreadsheet, you could make a month to month spending plan, track costs of doing business, or sort and compose a lot of information calculations in spreadsheets of Excels.