VBA loop to create named .csv files for all worksheets and workbooks in a folder
This code OK in 2007 for one workbook only.
You will have to add a loop to go through all workbooks in the folder.
Sub Make_New_Books()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
FileExtStr = ".csv": FileFormatNum = 6
For Each w In ActiveWorkbook.Worksheets
w.Copy
With ActiveWorkbook
.SaveAs Filename:=ThisWorkbook.Path & "\" & ThisWorkbook.Name _
& "_" & w.Name & FileExtStr
.Close
End With
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gord
On Sat, 5 May 2012 11:24:31 +0000, KQBats
wrote:
Hi all
I don't have a great deal of experience with VBA, but can usually muddle
my way through. I have drawn a blank with the following, however.
I have a folder containing multiple excel workbooks, all of which are of
the same structure. The workbooks contain multiple work sheets. I want
to write a macro that saves each worksheet within each workbook as a
separate .csv file that is named "NameofWorkBook_NameofWorkSheet". These
would all be saved into the existing folder.
I have been reading threads on similar topics and trying to meld them
together, but the best I have been able to do is save each worksheet
within a single workbook as the name of the worksheet. I am using Excel
2010. Any assistance with sample code, or directing me to where this has
previously been addressed would be most appreciated.
Thanks in advance...
|