Catch Word recovery warnings in document.open

T

Tony Gravagno

I have a Windows Service written in C# that opens the Word application
then opens a document, and starts running macros.

Very frequently the document.open will fail because "for some reason
as yet undiscovered" that document or another will be flagged in the
document recovery process. Opening the document manually shows dialog
"the document 'zzz' caused a serious error the last time it opened.
Would you like to continue opening it?" Well, a Service can't open
dialogs and ask a user what to do with old documents, so the
document.open is stuck, an exception is never thrown, the process
appears to be frozen.

I know I know, serious errors shouldn't be ignored. In this case it
seems to be a data error that throws the VBA into some place that I
have yet to determine. All I want to do is close the doc and the app,
restart the app open a new doc and keep going.

I've seen this question before but never any answer: Can I do
something in the initialization the application or the document
opening that bypasses this process and opens the document from
scratch, ignoring any previous errors?

I'm further concerned that when this stuff happens that an exception
isn't thrown, but there is no document.open timeout either (or maybe I
missed it). If I can get a 5 second timeout on the document open and
then check the doc to see if it's there then I can throw and catch my
own exceptions, but I can't do anything if it's frozen on the open. I
hope the answer isn't to manage this operation in another thread.

Any insight is appreciated.
Thanks!
Tony
TG @ removethispartNebula-RnD
..com
 
T

Tony Gravagno

Tony Gravagno said:
I have a Windows Service written in C# that opens the Word application
then opens a document, and starts running macros.

Very frequently the document.open will fail because "for some reason
as yet undiscovered" that document or another will be flagged in the
document recovery process. Opening the document manually shows dialog
"the document 'zzz' caused a serious error the last time it opened.
Would you like to continue opening it?" Well, a Service can't open
dialogs and ask a user what to do with old documents, so the
document.open is stuck, an exception is never thrown, the process
appears to be frozen.

I know I know, serious errors shouldn't be ignored. In this case it
seems to be a data error that throws the VBA into some place that I
have yet to determine. All I want to do is close the doc and the app,
restart the app open a new doc and keep going.

I've seen this question before but never any answer: Can I do
something in the initialization the application or the document
opening that bypasses this process and opens the document from
scratch, ignoring any previous errors?

I'm further concerned that when this stuff happens that an exception
isn't thrown, but there is no document.open timeout either (or maybe I
missed it). If I can get a 5 second timeout on the document open and
then check the doc to see if it's there then I can throw and catch my
own exceptions, but I can't do anything if it's frozen on the open. I
hope the answer isn't to manage this operation in another thread.

Any insight is appreciated.
Thanks!
Tony
TG @ removethispartNebula-RnD
.com

Follow-up : I need to catch this situation in VBA as well: The
document that I'm opening with C# is only a container to run VBA
macros. The macros themselves open other documents for processing and
apparently they are also spawning a dialog.

Thanks!!
 
T

Tony Gravagno

Tony Gravagno said:
Follow-up : I need to catch this situation in VBA as well: The
document that I'm opening with C# is only a container to run VBA
macros. The macros themselves open other documents for processing and
apparently they are also spawning a dialog.

One of the mysterious conditions that spawns a dialog is that the docs
I'm opening with the VBA are provided by another application, and that
app may not be done writing the doc before the Word VBA tries to read
it. This dialog displays with options for selection: " 'xfilename' is
locked for editing by 'another user'. Do you want to Open a Read Only
copy, Create a local copy and merge your changes later, receive
notification when the original copy is available."

What's weird is that the code beyond that documents.open statment
continues to execute anyway, so the dialog remains even though the
situation that caused it may be fixed.

Again, I'm just trying to stop these dialogs from popping up,
especially in a Service, and if they do I'd like to be able to detect
the situation in C# so that I can shutdown the process and log what
happened.

Ongoing thanks.
Tony
 
C

Cindy M -WordMVP-

Hi Tony,
Again, I'm just trying to stop these dialogs from popping up,
especially in a Service, and if they do I'd like to be able to detect
the situation in C# so that I can shutdown the process and log what
happened.
There is really no good way to trap or prevent message dialogs from
popping up when automating Word (or other Office apps, for that matter,
although Excel is better in that respect). That's one reason why MS
advises to NOT automate them on a server...

The only thing I've ever been able to find on this is a KB article
written for (classic) VB on detecting dialog boxes in OFFICE
applications and using SendKeys to close them.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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