Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Excel WorkSheet Bette Excel Discussion (Misc queries) 0 July 11th 07 03:42 AM
Export worksheet only tony wong Excel Programming 2 October 2nd 06 01:48 PM
Needed: worksheet export help mainemike Excel Discussion (Misc queries) 1 February 24th 06 02:59 AM
export favorites into worksheet adropinabucket Excel Programming 2 November 10th 04 09:39 AM
Export each worksheet to csv Trickster Excel Programming 3 November 2nd 03 11:36 PM


All times are GMT +1. The time now is 02:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"