Memory drain with large .DOT files?

R

Rick

I'm getting reports of occasional intermittent errors when my macros
run, and there doesn't seem to be any logical reason. I can't
reproduct the problem.

One of the .DOT files is 453 KB and another is 273 KB. Is there a
maximum recommend size for the .DOT beyond which strange things may
start to go wrong?

Also, I comment my code pretty heavily -- does commented code take up
memory space?
 
J

Jay Freedman

I'm getting reports of occasional intermittent errors when my macros
run, and there doesn't seem to be any logical reason. I can't
reproduct the problem.

One of the .DOT files is 453 KB and another is 273 KB. Is there a
maximum recommend size for the .DOT beyond which strange things may
start to go wrong?

Also, I comment my code pretty heavily -- does commented code take up
memory space?

There is a phenomenon known as "template bloat" that tends to happen
when the template's macros are repeatedly edited. Try the code cleaner
download from http://word.mvps.org/faqs/macrosvba/TemplateBloat.htm.

There is no specific file size that causes trouble; it depends much
more on what's causing the increased size. You could store megabytes
of AutoText and formatted AutoCorrect entries in it, and other than
taking longer to load, nothing unusual would happen.

Code comments do take memory space, but they don't affect execution
because the VBA interpreter ignores them when it's tokenizing the
code. Again, you could have megabytes of comments without causing
trouble. If you're distributing your template to other users, though,
it would be common courtesy to make a copy and remove most of the
comments from it to take up less room on their disks.
 
P

Pesach Shelnitz

Hi Rick,

In addition to Jay's suggestions, I would like to point out that such
intermittent errors can occur when code does not do enough to dispose of
unneeded objects and free up memory (to promote garbage collection). For
example, when your code is finished using an object that you created by Dim
and Set statements, you should add the following line (in which myObject
should be changed to the actual name of your object).

Set myObject = Nothing

I suggest that you review your code and add this line with the applicable
object name in the appropriate places.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top