PDA

View Full Version : Trapping w/ErrorHandler a Word crash



mansky
02-14-2008, 01:20 PM
Hi all,
I'd like to extend one of my error handlers in a Word macro to trap a Word crash. That is, the event where Word itself collapses and you get a dialog window asking whether or not you want to submit a report to Microsoft or not.

Can this be done? And can it be done from inside VB so that one can keep Word up? Or do I need a daemon script running in the background to catch such events?

Here's a snippet of code I'd like to extend:


Sub PasteSpecial()

On Error GoTo Error_Handle

Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine

Error_Handle:
If (Err.Number > 0) Then
If (ActiveDocument.Undo = True) Then
MsgBox ("Undo PasteSpecial successful. Please re-try.")
End If
End If
End Sub


The line I have a question about how to extend to handle a complete crash is in Red above.

Any ideas would be greatly appreciated!


Thanks!

Ed

fumei
02-15-2008, 11:01 AM
Wow. I am not sure. It depends on the timing of the "crash". If Word is truly crashed, it is not going to be running VBA code, now is it?

Can this be done?
Not from Word I think.

And can it be done from inside VB so that one can keep Word up?
I do not think so. Do you mean VBA? From inside VBA (either Word directly, or an instance of Word created by VBA)...I would have to have someone show me before I would believe that.

From inside VB (i.e. an instance of Word created by a VB application) - hmmmmm, maybe, but I doubt it.

Or do I need a daemon script running in the background to catch such events?
A background script may catch the event, but I seriously doubt it can do anything about what is happening to Word.


I would be far more concerned as to why it WOULD crash on a PasteSpecial - as that is where you are attempting to handle the error.

mansky
02-15-2008, 03:09 PM
Thanks. I suspected that indeed it isn't possible to re-construct the state Word was in once in after it's thrown an exception to the kernel and exited.

I also agree that it would be better to figure out and fix the initial reason why Word is crashing in the first place. I've added error handling code to my macros to catch and recover from User errors. Trapping errors during testing also helped me correct the code to eliminate errors in the code.

I just wanted to see if there was any way for VBA to trap a complete crash of Word before the exception was thrown and the Word core dumped from RAM.

Many thanks for the tips!

Ed

fumei
02-15-2008, 03:42 PM
Unless someone else can suggest something, I think the answer is no. If you DO find something definitely come back and tell us!