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.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

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>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,085
Messages
5,857,273
Members
431,867
Latest member
Dalorian

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