I have now done what you said step by step and agree... sorry for my
misguided responses earlier. If you say 'Yes' to accept the changes to
workbook B, you get no deactivate_event in workbook A. I have no answer (and
wish I'd kept my mouth shut).
Bill
"William" wrote in message
...
Hi Rob,
Thanks for your reply.
I understand that a deactivate event wont fire if it is not the active
workbook.
In the recreation of the problem I described, the workbook with the VBA
code
to detect the deactivate event is made active before I close it. I get
asked
if I want to save the other workbook while the first workbook is still
active
and when I click "Yes", there is no deactivate event.
Its possible that my explanation isn't clear. Here is the workbook setup I
had to recreate the problem.
1. I have two workbooks, "A" and "B", "A" has the VBA code to detect the
deactivate event (a messagebox). "B" is a normal workbook without the
code. I
have modified it but I have not saved it
2. I switch to "A" and save it. I then close the whole Excel app using the
"x" on the top right-hand corner
3. I get asked if I want to save "B". The window still shows the contents
of
"A". No deactivate event is fired
4. I click "Yes", "B" is saved and Excel closes down without any
deactivate
event being fired in the process for "A"
Am I right in assuming that "A" should catch a deactivate event?
"Rob Bovey" wrote:
Hi William,
A deactivate event can only be fired from an active workbook. In the
case described below, a deactivate event would fire in the first workbook
when you created the second workbook. You won't get another deactivate
event
in the first workbook when the entire Excel application is shut down,
because that workbook isn't active when Excel closes it.
You will get a deactivate event in the new unsaved workbook, because
that is the active workbook when Excel closes. I hope that all made
sense.
If you put message boxes in the Workbook_BeforeClose and
Workbook_WindowDeactivate events of both workbooks you'll see what I
mean.
--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/
* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm
"William" wrote in message
...
I've encountered a problem with Excel where the deactivate events (for
workbook and window) don't fire in certain situations.
The steps to re-create the problem a
1. You need to have two or more workbooks open in the same instance of
Excel
2. In one of the workbooks, enter some code to detect the deactivate
events
(eg. a message box) and save it
3. In another workbook, make some changes but don't save yet
4. Switch to the workbook with the VBA deactivate code and click the
'x'
(close) button for the whole Excel application
5. Excel should ask you to save the other workbook. Click 'Yes' and
Excel
should close but the deactivate event doesn't get fired for the active
workbook.
Does anyone else have the same problem?
It is important for what I am doing that there is a deactivate event
for
every activate event. I've not been able to find any information about
this
problem. The version of Excel I am using is 2000 with SP3. I know that
this
problem also occurs with Excel 2003.
If this is a known problem, can someone please direct me to where it is
documented and a workaround if available?
Thank you all