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.
This is very useful code. I modified a bit for my use, and will be using it a lot. Thanks Jeff
ReplyDelete