# VBA "Out of Memory"



## raskapopolis (Jun 14, 2007)

Hi all,

I'm running a Sub that does a lot of copying and pasting for reformatting purposes. After I run it a few times I can no longer copy and paste anything within Windows and specifically within VBA I get an "Out of Memory" (Error 7) error when I try to copy.

Now I've tried a few things already, such as covering everybit of the code with Application.CutCopyMode = False and have even copied a few lines of code from some websites for Subs that claim to empty the clipboard (no reason to assume they don't work generally, just not for me)

Merely accessing the Windows clipboard causes significant hanging and an error even if I do get so far as to hit the delete button. 

Any help would be greatly appreciated. 

Many thanks


----------



## draceplace (Jun 8, 2001)

A couple of things you may have already checked..
1. Low available disk space so that the swapfile can not grow
2. An upper limit (MAX) on the swapfile such that it can not get any larger.
3. Really go thru your code and make sure your not looping on a record or table ..i.e.Recursively enumerating files and folders and keeping a handle to them before performing processing. Rewriting your code to stream the content could improve things substantially.
4. "Erase myarray" The Erase command frees memory from *dynamic* arrays.
5. Resourses are freed up when the process ends you may want to look at breaking up the process into multiple parts that can be completed.
6. the Set myVarible = nothing is a common practice thats supposed to free memory. The whole 'garbage collector' thing is kind of a mystery...

Keep us posted, this is an interesting problem I expect to hit on day.


----------

