Saturday, 2 February 2013

Convert worksheets into csv files

I would like to share a macro with you that convert multiple sheets into multiple csv file within on click.

For this you need MS OFFICE 1997 or Higher version and window system.

Following are the instructions for convert xls ito csv.

1) Open your xls file in ms excel.
2) Press (ALT+F8), a popup will open.
3) type a name like "ExportSheetsToCSV" and click on "create" button.
4) Now new window will open, delete all data and past following data.
Sub ExportSheetsToCSV()
Dim wSheet As Worksheet
Dim csvFile As String
For Each wSheet In Worksheets
On Error Resume Next
wSheet.Copy
csvFile = CurDir & "\" & wSheet.Name & ".csv"
ActiveWorkbook.SaveAs Filename:=csvFile, FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
Next wSheet
End Sub


5) Now click on "Run" @ the top.
6) You can get all your csv files from the "c:\users\{username}\my documents\";