View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
William Benson[_2_] William Benson[_2_] is offline
external usenet poster
 
Posts: 230
Default Deactivate Events not Firing

Rob,

Great answer - I totally missed the active workbook issue in my answer!

In keeping with Simon's concern that a deactivate event be fired for every
time an activate event fires, he can have this reassurance: There is no way
his Deactivate has not fired by the time Excel closes either the Workbook or
the Application concerned. That is because it would have fired at the time
he either

opened another workbook so that it became the active workbook
created a new workbook so that it became the active workbook
switched from the workbook he is concerned to another open workbook
hid the workbook he is concerned with
.... can't think of any other scenarios.

Bill

"Rob Bovey" wrote in message
...
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