| Convert Excel XSL format to CSV format using VB Script |
|
The easiest way to convert an Excel file to CVS file is to open the file in Excel and the save it in CSV format. But what if you need to automate the process and have it run automatically a schedule interval. Well, you can use a script to perform a conversion from the Excel format to the CSV file format. Here is a script of how to do it. Dim objExcel 'As Excel.Application Dim xBook 'As Excel.Workbook 'Dim ObjXLSheet As Excel.Worksheet
Dim strFilename Dim strCSVFilename Dim a_strArgs
Dim CmdLine
strFilename = "c:\temp2\book1.xls" strCSVFilename = "C:\temp2\test.csv"
Set ArgObj = WScript.Arguments
if(ArgObj.length <> 2) then WScript.Echo "Invalid Argument. The accepted arguments are Excel source and CVS destination." else strFilename = ArgObj(0) strCSVFilename = ArgObj(1) 'a_strArgs = Split(Command$, " ")
Set objExcel = CreateObject("Excel.Application") 'Set xBook = objExcel.Workbooks.add 'xBook = objExcel.Workbooks.open strFilename, , True Set xBook = objExcel.Workbooks.Open(strFilename)
'Stop the alert popup when the file is saved. objExcel.DisplayAlerts = False xBook.SaveAs strCSVFilename, 23
'objExcel.DisplayAlerts = True xBook.Close ' Closes the workbook objExcel.Quit
Set objExcel = Nothing Set xBook = Nothing end if
|