ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Export worksheet to .csv (https://www.excelbanter.com/excel-programming/398267-export-worksheet-csv.html)

Omar[_7_]

Export worksheet to .csv
 
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?


Ken

Export worksheet to .csv
 
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



On Sep 27, 2:44 pm, Omar wrote:
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?




Ron de Bruin

Export worksheet to .csv
 
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


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Omar" wrote in message oups.com...
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?


Omar[_7_]

Export worksheet to .csv
 
Thanks Ron, that worked.

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

On Sep 27, 3:23 pm, "Ron de Bruin" wrote:
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

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm

"Omar" wrote in ooglegroups.com...
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?





All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com