ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to save sheets as separate workbooks (https://www.excelbanter.com/excel-discussion-misc-queries/47356-macro-save-sheets-separate-workbooks.html)

Zorro

Macro to save sheets as separate workbooks
 
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



Dave Peterson

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

Zorro wrote:

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


--

Dave Peterson

Ron de Bruin

Another one
http://www.rondebruin.nl/copy6.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Zorro" wrote in message . ..
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




Zorro

Thanks guys.

Zorro



"Ron de Bruin" wrote in message
...
Another one
http://www.rondebruin.nl/copy6.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Zorro" wrote in message
. ..
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







All times are GMT +1. The time now is 05:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com