PDA

View Full Version : Excel VBA Macro Crashing



kevkni
07-23-2012, 06:21 AM
Hi,

I'm trying to run an excel macro but at various stages it ends up causing MS Excel to crash.

The macro essentially opens an Excel file which is a blank cashflow template, saves the excel document as a new file with the name of the organisation in the filename, opens an older version of that particular organisations cashflow file, performs a series of "copy and paste" functions from the old template to the new template, and then saves and closes the template.

The macro then works it way down a list of organisation names, repeating the above process.

Sometimes the macro will reach the 5th or 6th organisation before Excel crashes, sometimes it will crash further down the list.

I've stepped through the macro line-by-line, and successfully completed the macro from start to finish without Excel crashing, but when it just "runs", it crashes.

Please can somebody help explain why this is happening!? :banghead:

Thanks
Kevin

CatDaddy
07-23-2012, 10:32 AM
post your code and the line it fails on

kevkni
07-24-2012, 12:53 AM
post your code and the line it fails on

That's part of the problem - there is no line where the code fails.

The macro doesn't bug out, just crashes excel. If you step through the macro line-by-line, through the entire, routine it works and does what it's supposed to. It's only when you run the macro at full speed that it crashes, and it crashes at different points, never the same place.

My only guess is it is something to do with memory usage, but the macro is only 6kb!

Bob Phillips
07-24-2012, 01:11 AM
Try inserting some debug.print statements in the code to see how far it gets sans stepping.

snb
07-24-2012, 02:49 AM
So why don't you post the whole code simply here ?
It has probably to do with referring to workbooks/worksheets.
If you start the macro manually a certain workbook/worksheet is the active one.
If you start the macro otherwise another workbook/worksheet may be the active one.