Thursday, December 19, 2013

Function to convert the xls file to Csv file

Function Convert_Excen_File_Xls_To_Csv (strFilePath) Dim strFile1 Dim strFile2 Dim objExcel Dim objWorkbook Convert_Excen_File_Xls_To_Csv = -1 If strFilePath <> "" Then strFile1 = strFilePath Else Convert_Excen_File_Xls_To_Csv = -1 End If strFile2 = Replace (strFile1, "xls","csv") Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open (strFile1) objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.SaveAs strFile2, -4143 objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.Close objExcel.DisplayAlerts = False objExcel.Application.Quit Set objExcel = Nothing Set objWorkbook = Nothing If err.number = 0 Then Convert_Excen_File_Xls_To_Csv = 0 End If End Function

No comments:

Post a Comment