View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Custom Addin, Excel Shutdown Problem

Hi Rod,

All add-ins are always shut down before any open workbooks. The only
time this might appear to be different is if the add-in is not an add-in but
really just a hidden workbook. My advice would be first to stop whatever is
causing the combo box change event to fire when your workbook closes.

If you can't do that, you can use a flag variable to bypass the event
when your workbook is shutting down. It would work something like this (I'm
assuming the combo box is on a worksheet):
---------------
In Module 1
---------------
Public bShutDown As Boolean

------------------------------------------
In the code module behind ThisWorkbook
------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
bShutDown = True
''' Other code
End Sub

------------------------------------------
In the code module behind the Worksheet
------------------------------------------
Private Sub ComboBox1_Change()
If bShutDown Then Exit Sub
''' Otherwise continue executing.
End Sub

Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"RodT" wrote in message
...
Hi, This one is probably for a bit of an Excel guru.

I have a custom home made addin installed in Excel2000. I
have a workbook which uses functions from the Addin, the
workbook also has a combo box which calls one of these
functions on it's CHANGE event.

If I close the workbook, then close excel everything is
fine. However, if I close Excel with the workbook loaded
I get a serious error which crashes Excel and causes
problems.

When I close Excel with the workbook loaded, the Addin
WorkBook_BeforeClose event is called, then the loaded
WorkBook_BeforeClose event is called, then the combo
CHANGE event is called, in this order (for some strange
reason). When the combo CHANGE event is called it tries
to call the addin function, but of course at this stage
the addin has been closed and this causes Excel to crash
in an unseemly manner.

I notice that some other addins installed by some software
stay loaded while this is happening. Why would my Addin
be closed BEFORE the workbook is closed ? This appears to
be the cause of the problem.

Any help appreciated.

Rod.