- Copy both files into the directory containing the files you want converted
- Run
excel-to-csv.bat
Note: This script requires Excel to be installed.
REM source: http://stackoverflow.com/a/11252731/715608 | |
FOR /f "delims=" %%i IN ('DIR *.xls* /b') DO to-csv.vbs "%%i" "%%i.csv" |
'source: http://stackoverflow.com/a/10835568/715608 | |
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 |
Doesnt Work for me,the cmd opens for a fraction of seconds and closes.
I have xlsx file,
Sorry i am new to scripting
It Worked Thankyou
There is a issue,It is not converting all the sheets,
this is fantastic. Saving me so much time. Thank you!
Super-useful! Works like a charm 🥇
Hello, how can I start the export from Column number 3 (to exclude the header) and eliminate the blank cells?
@rbxyz026
I'm really not sure. I didn't author the original script. I just modified it. I cited the original StackOverflow question in the files in this gist. Maybe there will be more information there. Hope that helps.
Is there a way to use ; as a delimiter instead of ,? I tried adding , Local:=True in line 20 but I get an error that a statement is expected after the : When I added , "Local:=True" no more errors but still the , is used instead of ; as delimiter.
Maybe one of you can help me out.
@suckerp the := thing doesn't work for the .vbs files, so to specify the wanted attrebute (Local) you should secify all the other attributes in order as mentioned in this documentation -> https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.saveas?source=recommendations
so what worked for me is changing the line 20 to this :
oBook.SaveAs dest_file, csv_format, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE
hope this helps for other people who visite this thred too as i suspect @suckerp won't benifit from a response 4 years later haha
Doesn't work in my situation...I run Windows 10 Enterprise.
The cmd window shows proper batch run, but I keep getting "Execution of the Windows Script Host failed. (Access is denied.)" from the Windows Script Host.
I shared the .xls file with full access to Everyone, but that didn't change anything.
Can anybody point this newbie in the right direction?
Thx