saving sheets as individual files

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
Hi all,

i have this code,
Code:
Sub Test1() 
Application.ScreenUpdating = False 
Dim ws As Worksheet, strPath$, strSheetName$ 
strPath = ThisWorkbook.Path & "\" 
For Each ws In Worksheets 
strSheetName = ws.Name 
Workbooks.Add 1 
ws.Cells.Copy Cells 
Sheets(1).Name = strSheetName 
ActiveWorkbook.SaveAs strPath & strSheetName & ".xls" 
Next 
Application.ScreenUpdating = True 
End Sub

What would i do to make it so once it has saved a file, it closes that file and continues on.

Currently, it just keeps them open, and the workbook it is going through has over 100 sheets, there fore i end up with 100 excel windows open.??

any ideas?
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

ktab

Well-known Member
Joined
Apr 21, 2005
Messages
1,297
try it like this:
Code:
Sub Test1()
Dim ws As Worksheet, strPath$, New_WB As Workbook

Application.ScreenUpdating = False
strPath = ThisWorkbook.Path & "\"

For Each ws In ThisWorkbook.Sheets
    ws.Copy
    Set New_WB = ActiveWorkbook
    With New_WB
        .SaveAs strPath & ws.Name & ".xls"
        .Close
    End With

Next
Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,335
Messages
5,595,569
Members
413,996
Latest member
mabelO

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
Top