Macro to delete a worksheet before Save As

Keith24249

New Member
Joined
Jun 18, 2011
Messages
21
Hi,
I would like to write a piece of code that would run when I click "Save As". I need it to delete a worksheet called "DATA" when I click Save As. I have searched many forums and googled it but nothing seems to work. The workbook is compiled in Excel 2007. Can anyone help. If you would like a copy of the workbook please let me know.
Regards
Keith
 
The one line (On Error Resume Next) only ignores errors. It doesn't prevent the code from executing. So if the code in the template worked before, it will still work.

Does the template still have a sheet named Data and is there a value in E2?

When you close the template, do you save it so the new value in E2 is saved and it will be incremented the next time?
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
When I do a "save as" I save the workbook (minus DATA worksheet) in a customer folder using the unique number generated by the code so that it can be re-opened ad infinitum.
At this stage the template isn't closed by me it closes itself, when I reopen it has a worksheet called DATA but the number does not increment by 1
Regards
Keith
 
Upvote 0
Well apparently you need to save the template so the value in "Data" E2 is saved and it will be increased when you open it the next time.

Whatever code you have that closes the template needs to include as save command.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

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