WINWORD.EXE still in Task Mgr after error?

E

Ed

(Running Office 2000 on Win 2000) I'll test-run a macro that opens a
docment, but error out the macro before it's finished and the document
opens. After correcting the error, I'll restart the macro, but now get a
warning that the doc is locked and can only be opened Read-Only. A check of
the Task Manager shows that, even after shutting down Word, I've still got a
WINWORD.EXE process running. (I'm assuming it's calling for the
to-be-opened doc? which would be why Word says its locked?) Is there
something I can put in my code that will prevent this by totally unloading
Word if an error occurs?

Ed
 
D

dz

Try using Error trapping in your test macros instead, such
as On Error Goto ErrorHander
[your code here]

ErrorHandler:

Msgbox "there's a problem in the macro"
End

This way, Word won't lock up and your document should be
unaffected.
 
J

Jezebel

Using an error handler is right, but using 'End' is absolutely wrong. 'End'
is included in VBA (and VB) for backward compatability with earlier versions
of Basic, but you should NEVER use it. Particularly in this sort of context,
it is likely to cause additional hard-to-diagnose crashes. In some cases the
mere presence of this instruction will cause your app to screw up. VB/VBA
apps are designed to terminate when all forms are unloaded and, in respect
of apps like Word and Excel, external references are released and errors are
dealt with.

The recommended structure is along these lines --

Sub MyFunction()

On Error Goto MyFunction_Error
[your code here]

MyFunction_Exit:
exit sub (or exit function, exit property)

MyFunction_Error:
Msgbox err.description & " (" & err.number & ")", vbcritical, "Error in
MyFunction"
resume MyFunction_Exit

End Sub






dz said:
Try using Error trapping in your test macros instead, such
as On Error Goto ErrorHander
[your code here]

ErrorHandler:

Msgbox "there's a problem in the macro"
End

This way, Word won't lock up and your document should be
unaffected.

-----Original Message-----
(Running Office 2000 on Win 2000) I'll test-run a macro that opens a
docment, but error out the macro before it's finished and the document
opens. After correcting the error, I'll restart the macro, but now get a
warning that the doc is locked and can only be opened Read-Only. A check of
the Task Manager shows that, even after shutting down Word, I've still got a
WINWORD.EXE process running. (I'm assuming it's calling for the
to-be-opened doc? which would be why Word says its locked?) Is there
something I can put in my code that will prevent this by totally unloading
Word if an error occurs?

Ed


.
 
E

Ed

Thank you both very much! I appreciate the help.

Ed

Jezebel said:
Using an error handler is right, but using 'End' is absolutely wrong. 'End'
is included in VBA (and VB) for backward compatability with earlier versions
of Basic, but you should NEVER use it. Particularly in this sort of context,
it is likely to cause additional hard-to-diagnose crashes. In some cases the
mere presence of this instruction will cause your app to screw up. VB/VBA
apps are designed to terminate when all forms are unloaded and, in respect
of apps like Word and Excel, external references are released and errors are
dealt with.

The recommended structure is along these lines --

Sub MyFunction()

On Error Goto MyFunction_Error
[your code here]

MyFunction_Exit:
exit sub (or exit function, exit property)

MyFunction_Error:
Msgbox err.description & " (" & err.number & ")", vbcritical, "Error in
MyFunction"
resume MyFunction_Exit

End Sub






dz said:
Try using Error trapping in your test macros instead, such
as On Error Goto ErrorHander
[your code here]

ErrorHandler:

Msgbox "there's a problem in the macro"
End

This way, Word won't lock up and your document should be
unaffected.

-----Original Message-----
(Running Office 2000 on Win 2000) I'll test-run a macro that opens a
docment, but error out the macro before it's finished and the document
opens. After correcting the error, I'll restart the macro, but now get a
warning that the doc is locked and can only be opened Read-Only. A check of
the Task Manager shows that, even after shutting down Word, I've still got a
WINWORD.EXE process running. (I'm assuming it's calling for the
to-be-opened doc? which would be why Word says its locked?) Is there
something I can put in my code that will prevent this by totally unloading
Word if an error occurs?

Ed


.
 

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