Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50186

Want to run Macro on multiple workbooks

$
0
0
Hi,

Quick question, I have the following Macro that will loop through all worksheets in a single workbook and dump each sheet into its own csv. It works great. The challenge is that I often need to go through multiple workbooks, perhaps 8 to 10, and it is time consuming, having to run the macro that many times.

Is there a way to, say, run through all of the xls files in a directory, or group of direcories, and generate files for all of the worksheets, each unique. I program enough just to be dangerous at it, and would like some input from someone who does this regularly, please.

Thanks in advance.

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

Viewing all articles
Browse latest Browse all 50186

Trending Articles