Export worksheet to .csv

O

Omar

I am trying to export multiple worksheets to .csv. This is what I have
so far:

For v = 1 To 7
Sheets(v).Select
ActiveWorkbook.SaveAs Filename:= _
"C:\" & .Name & ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
Next v


When I run the code, I get an error "Method Save As of object
'_WorkBook' failed".

Any ideas on how to fix this?
 
K

Ken

Omar
I think you just more information about where the .name is supposed to
come from.

Try:

For v = 1 To 7
Sheets(v).Select

ActiveWorkbook.SaveAs Filename:= _
"C:\" & activeworkbook.Name & ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
Next v

Good luck.

Ken
Norfolk, Va
 
R

Ron de Bruin

Try this

Sub test()
Dim a As Integer
Dim wb As Workbook
Application.ScreenUpdating = False
For a = 1 To ThisWorkbook.Worksheets.Count
ThisWorkbook.Sheets(a).Copy
Set wb = ActiveWorkbook
wb.SaveAs "C:\" & wb.Sheets(1).Name & ".csv", FileFormat:=xlCSV
wb.Close False
Set wb = Nothing
Next a
Application.ScreenUpdating = True
End Sub
 
O

Omar

Thanks Ron, that worked.

Ken, the only problem with that code is that it overwrites the same
file. I forgot about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top