Excel 2007: Flaky Macro

M

Mark Olbert

I've got a weird situation with a macro that I'm not sure how to go about debugging. This is all within Excel 2007.

From time to time (i.e., not always), the macro fails at a point where I first load a workbook and then immediately save it as an
Excel 2003 file. And it fails by crashing Excel.

Here's the weird part: if I single-step through the macro it never fails. In other words, there's nothing wrong with the logic.

This feels like some kind of file system dependency coupled to a hidden asynchronous behavior in Excel. Like the file load isn't
complete but the macro "thinks" it is and continues on.

I tried inserting Application.Wait <delay 5 seconds> into the flow, but that didn't prevent the crashes.

How the heck do I debug something that works in the debugger but fails in use??

- Mark
 
J

Jim Rech

In cases like that I've added a Stop to the code, saved the workbook and
opened it. If I get to the Stop I know the problem is after it so I moved
it ahead and tried again. Eventually you should find the line that fails.
You might even be able to figure out why<g>.

--
Jim
| I've got a weird situation with a macro that I'm not sure how to go about
debugging. This is all within Excel 2007.
|
| From time to time (i.e., not always), the macro fails at a point where I
first load a workbook and then immediately save it as an
| Excel 2003 file. And it fails by crashing Excel.
|
| Here's the weird part: if I single-step through the macro it never fails.
In other words, there's nothing wrong with the logic.
|
| This feels like some kind of file system dependency coupled to a hidden
asynchronous behavior in Excel. Like the file load isn't
| complete but the macro "thinks" it is and continues on.
|
| I tried inserting Application.Wait <delay 5 seconds> into the flow, but
that didn't prevent the crashes.
|
| How the heck do I debug something that works in the debugger but fails in
use??
|
| - Mark
 

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