Log in

View Full Version : Macro to fetch csv files



dhivya.enjoy
10-18-2013, 04:14 PM
Hi Team,

I need a macro which will get some values from user and on pressing a button i need csv files to be generated automatically. I need to generate some multiple csv files using this macro because we need to upload data in different tables.

Kindly provide me suggestions on below things

1.How to generate csv file from macro
2.How to generate multiple files at a time.

Regards
Dhivya

littleiitin
10-18-2013, 04:41 PM
Below is the code for saving workbook as csv for Multiple saving you can use loop



Sub SaveasCSV()
Dim strPath As String
Dim strFileName As String

strPath = "C:\Users\324954\Desktop\" ' Use your Path
strFileName = "MyFile" ' Use your File Name
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strPath & strFileName, _
FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
End Sub

dhivya.enjoy
10-21-2013, 05:44 PM
Below is the code for saving workbook as csv for Multiple saving you can use loop



Sub SaveasCSV()
Dim strPath As String
Dim strFileName As String

strPath = "C:\Users\324954\Desktop\" ' Use your Path
strFileName = "MyFile" ' Use your File Name
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strPath & strFileName, _
FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
End Sub


Hi littleiitin,

Your code perfectly works. Thanks for that. But it replaces the name of my current workbook as sheet2.csv.. or i can say it closes my macro sheet.

How to debug this. I guess something to do with the line below . Please help



ActiveWorkbook.SaveAs Filename:=strPath & strFileName, _