9
votes

I need to parse Excel work sheets. Now I save each individual work sheet as .csv and it works great. I use OpenCSV to parse the files etc. but to create those .csv files are a pain.

What would be the easiest and quickest way to save individual work sheets as .csv in Excel? I am assuming some kind of VBA macro would do the job, but since I am not a VBA programmer I have no idea how to do it. Maybe I can just record a macro somehow?

2
you could do it with VBA but you need to tell us more if you want precise help... - JMax

2 Answers

19
votes

Very roughly,

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
    ws.SaveAs "C:\docs\" & ws.Name & ".csv", xlCSV
Next

This does not include any error coding nor does it make allowances for sheet names that will lead to illegal file names. It all depends on how robust you need the whole thing to be.

3
votes

As a first answer, here is the code used to save a file to CSV:

ActiveWorkbook.SaveAs "C:\Marthinus.csv", fileformat:=6

More info about SaveAs