Save individual Excel sheets as CSV

前端 未结 2 1295
我在风中等你
我在风中等你 2020-12-31 15:01

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

相关标签:
2条回答
  • 2020-12-31 15:47

    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

    0 讨论(0)
  • 2020-12-31 16:05

    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.

    0 讨论(0)
提交回复
热议问题