How do I free memory in a Macro

Z

Zhongxia Hu

I use macro to process approximately 30mbs of .doc word document. I would
like to free all memory my macro use in one loop, how may I do that?
 
M

Malcolm Smith

I use macro to process approximately 30mbs of .doc word document. I
would like to free all memory my macro use in one loop, how may I do
that?


How is your code using the memory anyway? What sort of variables are you
holding and what are they holding?

- Malc
 
Z

Zhongxia Hu

Mr. Smith:

Thank you for asking. They are:
Dim CGcount As Double
Dim check As Boolean
Dim counter As Single
Dim oDocUndoStack As Object
Dim counter2 As Single
Dim check2 As Boolean
CGcount is a counter that counts no more than 500 letters through the letter
count command
counter will not go up greater than 40000
oDocUndoStack is the document, i guess it might be overflowing (the document
is more than 7000 pages long)
counter2 will not go up greater than 20

my macro stops at approximately 60000 loops, notify me "command not available"
 
M

Malcolm Smith

Crikey! The last time anyone called me Mr Smith it was the parole
officer.

A couple of things. First of all it would be more efficient to have all
of your counter variables as Long rather than Single or Double. These
are for holding real numbers whereas a counter would be an Integer.

Use Longs rather than (Short) Integers because the native size of a
variable in VBA is a Long anyway, so it's actually quicker to use a Long
than an Integer.

The oDocUndoStack actually isn't the document. It's just a pointer to the
document. Not quite the same thing.

What I have in a lot of my code where I am doing some serious work is the
following routine. You may wish to modify to make it work for yourself.


Private Sub PreventWordDeath(moWord As Word.Application, objDoc As
Word.Document)

On Error Resume Next


DoEvents

objDoc.UndoClear
objDoc.Repaginate

DoEvents

moWord.Options.Pagination = False
With moWord.Application
.ScreenUpdating = True
.ScreenRefresh
.ScreenUpdating = False
End With

DoEvents

End Sub

Hope that this helps.

- Malc
 

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