Exporting multiple tabs as .CSV files with the tab name being the folder and filename

Aug 4, 2010
Reaction score

I'm very new to programming in vba (only experience I have is with matlab and TI-83 basic).

I have excel sheets with 16 tabs and in order to do data processing I need to export these all to .csv files. To make this easier it would be great to save with the tab title as the folder it is saved in and the filename its saved as.

For example: C:\temp\"tab title"\"tab title"

I've been looking around for a few hours and can't seem to piece together the pieces of code I've found in a way that works. The best thing that I've come across saves all of the tabs in one file with their titles as filenames. Any help would be greatly appreciated! The code I referenced is below.

(I'm using office 10 beta on windows 7 64 bit)


Option Explicit
Sub testme()

Dim newWks As Worksheet
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
wks.Copy 'to a new workbook
Set newWks = ActiveSheet
With newWks
.SaveAs Filename:="C:\temp\" & wks.Name, FileFormat:=xlCSV
.Parent.Close savechanges:=False
End With
Next wks

MsgBox "done with: " & ActiveWorkbook.Name

End Sub


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