Saving Multiple worksheets

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
781
I have numerous workbooks in numerous different folders, each with 5-25 worksheets. I would like to do a script that would look to see what folder the open workbook resides in, parse out the worksheets from that workbook to that same directory & delete the original workbook.

I.E. in c:\test\1 resides a workbook (test.xls) wich consisits of worksheets 1,2,3,4,5. After the macro runs the directory would only consist of workbooks1.xls,2.xls,3.xls,4.xls,5.xls. Test.xl would be deleted.


Any direction woud be appreciated.
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
This has been very lightly tested (and I mean very lightly)...

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> ParseAndDelete()
    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet
    <SPAN style="color:#00007F">Dim</SPAN> wb <SPAN style="color:#00007F">As</SPAN> Workbook
    
    <SPAN style="color:#00007F">Set</SPAN> wb = ActiveWorkbook
    
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> wb.Sheets
        ws.Copy
        
        ActiveWorkbook.SaveAs wb.Path & Application.PathSeparator & _
            ws.Name & ".xls"
            
        ActiveWorkbook.<SPAN style="color:#00007F">Close</SPAN> <SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">Next</SPAN>
    
    wb.ChangeFileAccess xlReadOnly
    
    Kill wb.FullName
    
    wb.<SPAN style="color:#00007F">Close</SPAN> <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

Watch MrExcel Video

Forum statistics

Threads
1,122,719
Messages
5,597,736
Members
414,170
Latest member
Mdm

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