Consulting

Results 1 to 6 of 6

Thread: Solved: Remove a macro after execution?

  1. #1
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location

    Solved: Remove a macro after execution?

    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!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Modify this to suit your problem http://www.vbaexpress.com/kb/getarticle.php?kb_id=511 (removes itself (module) after execution of code)
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Awsome, thanks guys. (solved)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •