Purple_Mona
New Member
- Joined
- Feb 26, 2008
- Messages
- 4
Hi All,
I am currently working on a macro that takes each worksheets from a workbook, copies it as a separate workbook and saves it using that particular worksheet's name. For example, I have a report with various departments as separate worksheets (Admin, Finance, Legal, etc). I want to copy the 'Admin' worksheet as a separate workbook and save it as Admin.xls.
Probably an easy thing to do - but I haven't used VBA for years and I'm extremely rusty. Here's the code I've been trying to use - but when it gets onto the 2nd worksheet (ie. Finance, from the above example), it keeps throwing up an error of "Run Time Error '9': Subscript out of range." Can anyone help? Please?
Thanks.
Sub Separate_WkSheet()
Dim n As Integer
For n = 1 To Worksheets.Count
Worksheets
.Copy
ChDir "C:\Users\Main\Documents\Macros\Test_Folder"
ActiveWorkbook.SaveAs Filename:=Sheets
.Name
ActiveWorkbook.Close
Workbooks("Save_As_Worksheets").Activate
Next n
End Sub
I am currently working on a macro that takes each worksheets from a workbook, copies it as a separate workbook and saves it using that particular worksheet's name. For example, I have a report with various departments as separate worksheets (Admin, Finance, Legal, etc). I want to copy the 'Admin' worksheet as a separate workbook and save it as Admin.xls.
Probably an easy thing to do - but I haven't used VBA for years and I'm extremely rusty. Here's the code I've been trying to use - but when it gets onto the 2nd worksheet (ie. Finance, from the above example), it keeps throwing up an error of "Run Time Error '9': Subscript out of range." Can anyone help? Please?
Thanks.
Sub Separate_WkSheet()
Dim n As Integer
For n = 1 To Worksheets.Count
Worksheets

ChDir "C:\Users\Main\Documents\Macros\Test_Folder"
ActiveWorkbook.SaveAs Filename:=Sheets

ActiveWorkbook.Close
Workbooks("Save_As_Worksheets").Activate
Next n
End Sub