need macro to copy worksheets into individual workbooks

neov

Board Regular
Joined
Oct 3, 2003
Messages
67
Hi all. Thanks in advance.

Have a workbook with approximately 25 worksheets in it.

I want to copy/paste/value each worksheet and save it as it's own workbook.

My code doesn't work, it hangs up on ws.copy every single time, on Excel 2007 and prior versions.

Does anyone have working code for something like this?

FYI, my current code is : - I had posted in another thread, but the title was misleading!

Sub SaveWS()
Dim wb As Workbook
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Copy
Set wb = ActiveWorkbook
wb.SaveAs "t:\dir1\expenses\" & ws.Name & ".xls"
wb.Close False
Next ws

End Sub
 
Thomas

A solution to what?:eek:

Perhaps it would be better if you started a new thread.:)
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I have a workbook with 255 individual spreadsheets that I would like to save with the same names as 255 separate files - one Excel workbook with one sheet for each of the 255 spreadsheets. None of the posted solutions work.
 
Upvote 0
Yes, I need each sheet in a separate workbook. I have it just about complete except that I need to close and save the each workbook as they are created. Should not be too hard to complete that last step.

Thanks for your help.
 
Upvote 0
Not sure if you are talking to me Thomas .
In case you are using the code from the link I've posted the new WB should be created, saved and closed automatically ... no need for you to do it.
If you want to get rid of the extra sheets in each new WB add this to the code:

Code:
Dim sh As Worksheet
    For Each sh In ThisWorkbook.Worksheets
      If Application.WorksheetFunction.CountA(sh.Cells) = 0 Then
        Application.DisplayAlerts = False
        sh.Delete
        Application.DisplayAlerts = True
      End If
    Next
 
Upvote 0
That should do it Thomas (you will find the new WB in your "documents")
If you need a different path maybe you should start a new post.

Code:
Sub Macro1()
For Each sh In ThisWorkbook.Worksheets
   sh.Copy
   ActiveWorkbook.SaveAs Filename:=sh.Name, FileFormat:=xlNormal
   ActiveWindow.Close
Next sh

End Sub
 
Last edited:
Upvote 0
hi Guys,

check out Mr Excel podcast episode 894 the code is already there just needs changed to suit xls or xlsx. file
 
Upvote 0
HI thomas,
Not sure if you are still interested in splitting workbook. Here is a set of codes. Replace the file path to suit your case
Code:
Sub Macro3()
Dim d As String, b As String
Dim a As Integer
For a = 1 To Sheets.Count
b = Worksheets(a).Name
Sheets(a).Select
Sheets(a).Copy
d = "C:\Documents and Settings\HNravi.RAVI\Desktop\" & b & ".xls"
ActiveWorkbook.SaveAs d
ActiveWorkbook.Close
Next a
End Sub
On running the macro, it saves each sheet as a new workbook
Ravi
 
Upvote 0

Forum statistics

Threads
1,222,697
Messages
6,167,702
Members
452,132
Latest member
Steve T

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top