Workbook_WindowDeactivate (Xl 2003)

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Workbook_WindowDeactivate (Xl 2003)

Post by Zauberkind »

Greetings,
the new Zauberkind huh? of the week. :scratch:

I have a fairly large (7Mb) workbook which I haven't posted here.

It has a peculiar characteristic: when it's open with another workbook that shouldn't be saved, I have to close the App twice!
~~~~~~~~~~~~~~~~~~~~~
Example:
- open wb0
- open wb1 (wb1 is now ActiveWorkbook)
(both workbooks need to be updated)
- close app
- dialog: do you want to save wb1? - No
- dialog: do you want to save wb0? - Yes
...nothing happens
- close app
- no dialog
- wb0 is saved
- wb1 is not saved
...app closes
~~~~~~~~~~~~~~~~~~~~~
After much paring down, I came to the conclusion that the problem is connected with the WindowDeactivate event.
It doesn't need to have code, it just needs to be defined. Whether a WindowDeactivate event handler is defined in wb1 seems to be irrevant.

Is this a known problem? I couldn't find anything useful on the Net.

To duplicate the problem, I've attaced a WB with stripped down code in the Workbook:

Code: Select all

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
End Sub ' Workbook_WindowDeactivate
To try it out, make two copies, open both, close Excel, save at the second prompt, not at the first. The order seems to be important.
I'm using Excel2003, and I'd be interested to know if this problem is known, reproducible, or fixed in later versions.

TIA
Zk
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Workbook_WindowDeactivate (Xl 2003)

Post by HansV »

It works exactly the same in Excel 2010 if I select File > Exit
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Workbook_WindowDeactivate (Xl 2003)

Post by Zauberkind »

So I guess the answer is: not known, reproducible, not fixed in later versions".
Thanks for the info.
The solution seems to be: don't DO that!
ZK

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Workbook_WindowDeactivate (Xl 2003)

Post by HansV »

The same problem is mentioned in It takes two clicks to shut down Excel on the MrExcel site.
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Workbook_WindowDeactivate (Xl 2003)

Post by Zauberkind »

Capo!
Can I ask what rubric(s) you used to find that? What engine?
I didn't find it, but maybe I was searching from the wrong end.
ZK

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Workbook_WindowDeactivate (Xl 2003)

Post by HansV »

I typed the search words excel windowdeactivate problem into Google.
The first hit was the MSDN reference for WindowDeactivate and the second one was not relevant. MrExcel was the third hit, and the short description drew my attention:
x1232.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Workbook_WindowDeactivate (Xl 2003)

Post by Zauberkind »

I did a little more poking around.
The problem occurs if either the Workbook_WindowDeactivate or Workbook_Deactivate event handlers are defined.
The problem does not occur if the workbook with the handler is the ActiveWorkbook.
The problem does not occur if the Worksheet_Deactivate event is handled.

Unfortunately I need the Workbook_Deactivate event to show/hide my custom menu bars.
I guess I'm out of luck!

ZK

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Workbook_WindowDeactivate (Xl 2003)

Post by HansV »

I don't know a solution or workaround for this problem, but you might provide an instruction for the user, along the lines of "If you're trying to quit Excel and the workbooks don't close immediately, don't panic. Just try again."
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Workbook_WindowDeactivate (Xl 2003)

Post by Zauberkind »

...on the other hand, if they panic, the first they'll do is to try again.

Insanity - the idea that if you repeat a failed solution often enough, you'll succeed!

ZK