Releasing RAM while a macro is running

C

Charlie Mac

VBA Gerus,

I have created a macro that scans large documents for text patterns
and adds comments when a pattern (e.g., several words) is detected. My
problem is that when it is run on documents longer than 30 pages it
slows down and on 200+ page documents, it appears to exhaust RAM and
stop. Is it possible to release/refresh RAM while a macro is running
without erasing array and variable values? Is there a link that
offers performance tips for macros?

Thanks from Texas
 
K

Klaus Linke

VBA Gerus,

I have created a macro that scans large documents for text patterns
and adds comments when a pattern (e.g., several words) is detected. My
problem is that when it is run on documents longer than 30 pages it
slows down and on 200+ page documents, it appears to exhaust RAM and
stop. Is it possible to release/refresh RAM while a macro is running
without erasing array and variable values? Is there a link that
offers performance tips for macros?

Thanks from Texas


Hi Charlie,

I guess you're doing a lot of Find/Replace? Word can be forced to create a
lot of temporary files if you do that, so it can undo all those changes.

You could try if clearing the Undo-buffer now and then helps:
ActiveDocument.UndoClear

And/Or have the macro save the document:
ActiveDocument.Save

If your document is just text (no tables, text boxes, or fields), you could
read the whole text into a string (sText = ActiveDocument.Content.Text), and
try to do as much of the work as possible on the string rather than on the
document.
Say in the string, you find some position you want to insert text (with say
InStr), you can then set a range to that position in the document, and
insert your comment.

If these tips don't help, maybe post some code you use that's too slow...
Regards,
Klaus
 
C

Charlie Mac

Klaus,

Sorry it took me so long to get back.... Thank you for your
suggestion...the ActiveDocument.UndoClear works great.

Take care,

Charlie in Texas
 

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