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?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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