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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Perhaps if the book/sheet was/were protected and to convert formulas to values:

Code:
Sub SaveWS()
Dim wb As Workbook
Dim ws As Worksheet
ThisWorkbook.Unprotect Password:="xyz"
For Each ws In ThisWorkbook.Worksheets
    ws.Unprotect Password:="xyz"
    ws.Copy
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
    Set wb = ActiveWorkbook
    wb.SaveAs "T:\dir1\expenses\" & ws.Name & ".xls"
    wb.Close False
    ws.Protect Password:="xyz"
Next ws
ThisWorkbook.Protect Password:="xyz"
End Sub
 
Upvote 0
nothing is protected

still getting "Run Time Error '1004'
Method 'Copy' of object '_Worksheet' Failed
 
Upvote 0
there are several hidden sheets, but the macro crashes before it does anything at all
 
Upvote 0
thx Kevin, this is the first code that has worked for me

Sub SplitSheets()
Dim W As Worksheet
For Each W In Worksheets
W.SaveAs ActiveWorkbook.Path & "/" & W.Name
Next W
End Sub

Now I just need a macro to copy/paste-special value an entire sheet and set the print attributes, and I'll be all set - should be able to figure that out by recording.

Thanks again.
 
Upvote 0
neov

Have you actually checked what the last code you posted does?

I think you might find it might save a little bit more than the individual sheets.:)
 
Upvote 0
doh - it appears to save the entire file, but with a different worksheet name every time....so I'm back to square one!
 
Upvote 0
Yes, same thing for me. It copied the entire worksheet into non-excel files with the name of each worksheet. I am still searching for a solution. :mad:
 
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