3

I have Excel 2010.

Found this: Batch XLS to CSV Converter

But I actually need to export all excel worksheets as individual CSV files. Not sure if it works that way. Also if I were to use the above method, how do I actually use a VB script? (not familiar with programming)

3
  • using Windows 7
    – AKA
    Sep 20, 2012 at 23:35
  • Just use COM from Python to spit them out. Sep 20, 2012 at 23:44
  • To use Excel's VBA capabilities, press Alt + F11. Then go to 'Insert' -> 'Module'. Your code goes in the text window that opens.
    – Excellll
    Sep 21, 2012 at 13:29

1 Answer 1

2

Here is a cleaned-up version of the script from the post to which you linked:

Option Explicit

Const xlXMLSpreadsheet = 46
Const xlCSV = 6

Dim xl, wb, ws

Dim args : Set args = WScript.Arguments

If args.Count <> 1 Then
  WScript.Echo "Syntax: cscript " & WScript.ScriptName & " filename"
  WScript.Quit(1)
End If

Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Open(args(0))

xl.DisplayAlerts = False
For Each ws In wb.Worksheets
 ws.activate
 wb.SaveAs CreateObject("Scripting.FileSystemObject").GetBaseName(args(0)) _
   & "_" & Replace(ws.Name, " ", "_") & ".csv", xlCSV
Next
xl.DisplayAlerts = True

wb.Close False
xl.Quit
WScript.Quit

It should do what you want. You call it like this from a command prompt:

cscript SCRIPT.vbs INPUT.xls

It creates output files INPUT_SHEETNAME.csv.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .