View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Martin Brown Martin Brown is offline
external usenet poster
 
Posts: 230
Default Iterative consolidation macro can't complete - memory overload?

On 27/11/2014 17:51, Stuart wrote:
The following code works fine on one two or maybe three passes through... and then Excel crashes.

It simply loops through a folder of excel files one by one. It opens one, opens the new template, and copies and pastes a bunch of data from the old to the new template. Then it saves the new template in a new folder, with the same filename as the original. Then it repeats for the next original file.

Each file, and the template, is about 1mb in size (xlsx), and there 50 or so files in the set, i.e. the code needs to complete 50 loops without crashing!

I don't know why it crashes, as the code works for one loop, so why not all loops?! It just hangs with the regular "RESTART EXCEL?" dialog box.


I have seen something a bit like this because Excel file handling didn't
like the name of one file. Another time it failed on a magic boundary
through missing out the 256th file or something like that.

A memory problem? Can anyone advise of a better way to do this, or how to manage the memory issue properly if that is indeed the problem?

Thanks in advance for any life saving help!!


All I can suggest is add debug.print waypoints to the code so that you
at least know which line it fails at. I have my suspicions that on error
handling is hiding something nasty that later causes trouble.

It would help to know which version of XL you are on. VBA on XL2007 was
pretty unreliable unless patched up to the eyeballs with updates.

It would be interesting to know if it still crashes if you step through
it line by line. Some of the race conditions present in XL2007 lead to a
situation where using VBA at full speed the execution thread might or
might not fail due to data structures not being fully initialised.

--
Regards,
Martin Brown