Macro to save sheets as separate workbooks

  • Thread starter Thread starter Zorro
  • Start date Start date
Z

Zorro

can anyone help with a macro to save each worksheet as a separate book
(named as its sheet name) to a given folder (C:\mydocs\myfolder)?

Many thanks
Zorro
 
Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet

For Each wks In activeworkbook.worksheets
wks.Copy 'to a new workbook
Set newWks = ActiveSheet
With newWks
Application.DisplayAlerts = False
.Parent.SaveAs Filename:="C:\mydocs\myfolder\" & .Name, _
FileFormat:=xlworkbooknormal
Application.DisplayAlerts = True
.Parent.Close savechanges:=False
End With
Next wks

End Sub

It also overwrites any existing file (if one exists).

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

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

Back
Top