Discussion:
DocumentBeforeClose problems
(too old to reply)
Alex
2005-08-17 02:48:13 UTC
Permalink
Hello,

The DocumentBeforeClose event gives me grief.

The problem is that I have to perform a certain cleanup operation when a document is closed.

Unfortunately, DocumentBeforeClose is called before the user is presented with the "Document changed, do you want to save?" dialog, which can cancel the close.

So, I do not know whether the document was actually closed.

Is there a way around it?

Thanks.


Best wishes,
Alex.
--
Address email to user "response" at domain "alexoren" with suffix "com"
Jean-Guy Marcil
2005-08-17 03:52:47 UTC
Permalink
Post by Alex
Hello,
The DocumentBeforeClose event gives me grief.
The problem is that I have to perform a certain cleanup operation
when a document is closed.
Unfortunately, DocumentBeforeClose is called before the user is
presented with the "Document changed, do you want to save?" dialog,
which can cancel the close.
So, I do not know whether the document was actually closed.
Is there a way around it?
In your BeforeClose event, check the value of
ActiveDocument.Saved
If it is false, then the document is "dirty" and Word will ask the user if
they want to save.
So, knowing that, create your own messagebox asking the user if they want to
save, if not, switch the value to True and carry on with your event, if they
do, save and then carry on with your event code.

I have not tested it (It is late here...), but I think it should work
because I remember doing something like a few years ago.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
***@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Michael Bauer
2005-08-17 06:12:29 UTC
Permalink
Am Tue, 16 Aug 2005 22:48:13 -0400 schrieb Alex:

Alex, I use DocumentChange. In this event I store the Documents.Count
and compare with previous values. If the count has decreased then I
search for my Document(s) to see if it´s (or one of them is) gone.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Post by Alex
Hello,
The DocumentBeforeClose event gives me grief.
The problem is that I have to perform a certain cleanup operation when a document is closed.
Unfortunately, DocumentBeforeClose is called before the user is
presented with the "Document changed, do you want to save?" dialog,
which can cancel the close.
Post by Alex
So, I do not know whether the document was actually closed.
Is there a way around it?
Thanks.
Best wishes,
Alex.
Alex
2005-08-18 18:04:59 UTC
Permalink
Hello Michael,
Post by Michael Bauer
Alex, I use DocumentChange. In this event I store the Documents.Count
and compare with previous values. If the count has decreased then I
search for my Document(s) to see if it´s (or one of them is) gone.
Excellent idea, I re-used it.

Except that there is no need to search since if the number of documents has changed, it means that the previously current document was closed.

I think this approach should also work for Window objects in conjunction with the WindowActivate event.


Best wishes,
Alex.
--
Address email to user "response" at domain "alexoren" with suffix "com"
Loading...