Can A Macro delete the macro button used to run it?


Posted by Chris Rock on July 06, 2001 9:33 AM

I have a template with a macro button on it. The workbooks created by that template have a macro button on them that runs a report, but the report can only be run once. If the button is accidentally pressed again, an error pops up.

Can I add code to the macro that will delete the button from the worksheet while the macro is running?

Thanks in advance.



Posted by Joe Was on July 06, 2001 9:46 AM

Yes, open the notepad, record a macro where you delete the button, stop the recorder. Open the macro copy it to the notepad. Exit your application without saving it. Re-open your application then copy the macro code from the notepad to the end of your macro.

Macros are run in order of code top to bottom, so if the macro is done with the code above and it gets to your delete code it will delete the button. You will need a way to redo the button.
So set up a Hot-key macro to build the button and assign it to your macro! JSW