Saving Multiple worksheets

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
787
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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>
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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