Pages

Showing posts with label VBS. Show all posts
Showing posts with label VBS. Show all posts

Wednesday, January 20, 2016

Convert CSV file from Excel in batch mode by using DOS command


By using below script, you can convert CSV file from Excel (xls /xlsx) file in batch mode silently. Please follow below steps to convert your required file.

Step-01:  Copy the below VB script in a text file, paste it & save the file as “ExcelToCSV.vbs”.

if WScript.Arguments.Count < 2 Then
    WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv <xls/xlsx source file> <csv destination file>"
    Wscript.Quit
End If

csv_format = 6

Set objFSO = CreateObject("Scripting.FileSystemObject")

src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))

Dim oExcel
Set oExcel = CreateObject("Excel.Application")

Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)

oBook.SaveAs dest_file, csv_format

oBook.Close False
oExcel.Quit

Step-02: Copy the below script in a text file & save the file as “ExcelToCsv.bat”.

FOR /f "delims=" %%i IN ('DIR *.xls /b') DO ExcelToCSV.vbs "%%i" "%%i.csv"

Step-03: Now copy the “ExcelToCSV.vbs” & “ExcelToCsv.bat” files in your expected folder, where your EXCEL file is stored.

Step-04: Now double click on the ExcelToCsv.bat file & wait to complete the conversion.


Thank You.