Sometimes you may need to create a new workbook for each sheet, it seems very boring to do it manually, in this situations, you can use the following macro.
Create a New Workbook for Each Sheet
'------------------ Modules ------------------
Sub SheetsToWorkbooks()
'Step 1: Declare all the variables.
Dim ws As Worksheet
'Step 2: Turn screen updating off to speed up your macro code
Application.ScreenUpdating = False
'Step 3: Start the looping through sheets
For Each ws In ThisWorkbook.Worksheets
'Step 4: Copy the target sheet to the new workbook
ws.Copy
'Step 5: Save the new workbook with sheet name.
ActiveWorkbook.SaveAs ThisWorkbook.path & "\" & ws.Name
ActiveWorkbook.Close SaveChanges:=True
'Step 6: Loop back around to the next worksheet
Next ws
'Step 7: Turn screen updating on
Application.ScreenUpdating = True
End Sub
This macro will save each worksheet as a new workbook with the sheet name to the folder that source workbook is in. The new workbooks are closed after they are saved.
How This Macro Works
- Step 1 declares a object variable. The ws variable creates a memory container for each worksheet the macro loops through.
- In Step 2, we use
Application.ScreenUpdating = False
to turn screen updating off to speed up this macro code. - In Step 3, the macro starts looping through the sheets. The use of the ThisWorkbook object ensures that the active sheet that is being copied is from the workbook the code is in, not the new workbook that is created.
- In Step 4, we use Copy method to copy the worksheet to a new workbook.
- In Step 5, We save this new workbook in the same directory (ThisWorkbook.Path) as your original workbook, with the same filename (ws.Name) as the copied sheet.
- Step 6 loops back to get the next sheet.
- Finally, you should turn screen updating on use
Application.ScreenUpdating = True.
How to Use This Macro
Most VBA code should be placed in Standard Modules unless specified.
If you see a comment '------------------ Modules------------------
in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?
The following steps teach you how to put VBA code into a Standard Module:
- Activate the Visual Basic Editor by pressing ALT + F11.
- Right-click the project/workbook name in the Project Window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
- Click Run button on the Visual Basic Editor toolbar.
- For more information, learn this course: Programming with Excel VBA