Skip to content

Instantly share code, notes, and snippets.

@vallabhiaf
Forked from tonyerskine/README.MD
Created April 29, 2020 10:29
Show Gist options
  • Save vallabhiaf/b8bb5f8e160264bb95c10b45fe523f71 to your computer and use it in GitHub Desktop.
Save vallabhiaf/b8bb5f8e160264bb95c10b45fe523f71 to your computer and use it in GitHub Desktop.
Windows Script to Convert Excel Files to CSV

Instructions

  1. Copy both files into the directory containing the files you want converted
  2. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment