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?
(1) Keep selecting all sheets. If not, you can check the checkbox before Worksheet name to select all sheets; (2) Check the Specify save format option; (3) Click the box below Specify save format option, and select CSV (Macintosh)(*.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With