View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Omar[_7_] Omar[_7_] is offline
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?