PDA

View Full Version : Solved: Remove a macro after execution?



debauch
03-29-2006, 12:02 PM
If this post already exists I apologize, as I could not find anything similar.

Is there a way to either :
- Clear vba code after macro execution
- remove macro altogether after execution

?????

I though I have seen, or read this before, but cannot find the source. Thanks!

mdmackillop
03-29-2006, 12:59 PM
I don't believe you can run a macro which requires its own removal. How would you reach End Sub? You could add some other code to the workbook to remove all code except itself, for which I believe there may be examples in the KB
Regards
MD

johnske
03-29-2006, 02:38 PM
Modify this to suit your problem http://www.vbaexpress.com/kb/getarticle.php?kb_id=511 (removes itself (module) after execution of code)

mdmackillop
03-29-2006, 02:41 PM
footinmout

johnske
03-29-2006, 02:48 PM
Hi Malcolm,

You're too quick, I just came back to edit and add:

I'll try to explain - The code can reach End Sub because is running from the 'compiled' code, not from within the code module (which is what is being deleted). Saving the workbook after the code module's deleted then deletes the compiled code...

HTH,
John :)

debauch
03-29-2006, 03:14 PM
Awsome, thanks guys. (solved)