Consulting

Results 1 to 10 of 10

Thread: Solved: what is a code cleaner

  1. #1

    Solved: what is a code cleaner

    Hi all,

    Can someone please explain to me in simple terms what a VBA code cleaner does ?

    What is "a build up of junk code" ?
    If i don't write it where does it come from ?

    I?m new to Vba (u may have guessed) and any help would be appreciated.

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    VBA has a tendency to bloat, it just seems to grow for no apparent reason (nothing that has been added code-wise).

    The solution to this problem is to export all of the code modules and re-import them. The re-import seems to refresh everything and remove that bloat.

    Rob Bovey has written an indispensable addin that does it all automatically for you, http://www.appspro.com/Utilities/CodeCleaner.htm. I always clean my production code before releasing.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Quote Originally Posted by xld
    VBA has a tendency to bloat, it just seems to grow for no apparent reason (nothing that has been added code-wise).
    Since VBA is a smaller version of Visual Basic, does the same phenomenon occur in Visual Basic as well?
    Brandtrock




  4. #4
    Does this bloating happen with all code, big and small?
    I ask because I’ve not experienced any change to any of my code.
    Is it something that is very rare?

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You will need to run the code cleaner on your files and compare the filesize before and after running it.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Brandtrock
    Since VBA is a smaller version of Visual Basic, does the same phenomenon occur in Visual Basic as well?
    That's a good question, and whilst I do not know for sure, I think I can take a good stab at it. As VB holds all of the project modules as separate files, I would think not. The bloat seems to be incurred by some interaction with VBA/Excel in the files, as they are conatined within the host application.

    And I have never noticed it in VB.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by jazznaura
    Does this bloating happen with all code, big and small?
    I ask because I?ve not experienced any change to any of my code.
    Is it something that is very rare?
    You won't notice any change to your code necessarily, it doesn't actually corrupt the code, it just bloats the file.

    Test it and see. Save the workbook, and note its size. Then clean it and save it again, and see if it is smaller.

    When I say it doesn't corrupt the file, it does occasionally mess it up. many times I have had inexplicable things happening, code doing things I knew it couldn't do, which were then solved by cleaning.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Quote Originally Posted by xld
    That's a good question, and whilst I do not know for sure, I think I can take a good stab at it. As VB holds all of the project modules as separate files, I would think not. The bloat seems to be incurred by some interaction with VBA/Excel in the files, as they are conatined within the host application.

    And I have never noticed it in VB.
    Thanks for the reply Bob. You mention that some interaction between VBA/Excel seems to be the cause. Is this unique to Excel, or does it happen in the other MS applications that are VBA compatible? What about non MS products such as Corel Draw and AutoCAD? Have you, or anyone else, seen those files bloat as well?

    Just curious mostly, I haven't got the time right now to do any research beyond reading the replies here. I appreciate the information that has been shared thus far. Thanks again.

    Regards,
    Brandtrock




  9. #9
    Thanks XLD for all the info.
    I was concerned that additional code was generated but now I understand better.
    Thanks,

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    MHO:

    I believe that the code bloat and the eventual instability comes from extensive editing on the VBA modules.

    The VBA editor garbage collection/cleanup leaves a lot to be desired, and seems to eventually currupt the VBA by leaving pieces of deleted code around.

    Many times one of my well behaved workbooks will start acting erratic (e.g. different results for the inputs) or even crashing Excel after one too many cut and pastes or other edits

    Cleaning the code will usually fix this sort of thing, and get me back to just the usual kind of errors I make.

    Paul

Posting Permissions

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