PC Review


Reply
Thread Tools Rate Thread

before close event

 
 
mark
Guest
Posts: n/a
 
      26th Sep 2008
I wrote an add-in which I load on the Workbook_Open event, and close on the
Workbook_BeforeClose event.

I just noticed that if you go to close the file, but then hit Cancel, so
you're still in the file, my Add-In has been unloaded.

This means that the BeforeClose event is firing prior to the pressing of the
Cancel button, which then keeps the workbook open.

It's not a huge deal, but, someone will likely see this as a bug, if I leave
it this way. Ideas on how to trap the press of the Cancel button, and reload
the Add-In?

I'm not sure that's most efficient, though... I'd rather not unload the
Add-In until the workbook is really going to close.

Ideas?
Thanks.
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      26th Sep 2008
Instead of using the on open and on close events try using the Addin Install
and Addin Unistall events. They do not get fired on Cancel. Note that your
addin would not be alone in this category. There are lots of addins that fall
into this trap. Even commercial product such as Oracle's (Hyperion) Essbase
addin unloads in this manner.
--
HTH...

Jim Thomlinson


"mark" wrote:

> I wrote an add-in which I load on the Workbook_Open event, and close on the
> Workbook_BeforeClose event.
>
> I just noticed that if you go to close the file, but then hit Cancel, so
> you're still in the file, my Add-In has been unloaded.
>
> This means that the BeforeClose event is firing prior to the pressing of the
> Cancel button, which then keeps the workbook open.
>
> It's not a huge deal, but, someone will likely see this as a bug, if I leave
> it this way. Ideas on how to trap the press of the Cancel button, and reload
> the Add-In?
>
> I'm not sure that's most efficient, though... I'd rather not unload the
> Add-In until the workbook is really going to close.
>
> Ideas?
> Thanks.

 
Reply With Quote
 
mark
Guest
Posts: n/a
 
      26th Sep 2008
with you part way...

but, on the test I just did, the Add-In doesn't uninstall when I close the
workbook, which is what I want.

So, tracking back, I still need something to fire the Add-In Uninstall Event.

I noticed that the BeforeClose had a parameter (Cancel as Boolean) that I
wasn't using. I could trap that.

Or did I miss something in what you said?


"Jim Thomlinson" wrote:

> Instead of using the on open and on close events try using the Addin Install
> and Addin Unistall events. They do not get fired on Cancel. Note that your
> addin would not be alone in this category. There are lots of addins that fall
> into this trap. Even commercial product such as Oracle's (Hyperion) Essbase
> addin unloads in this manner.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "mark" wrote:
>
> > I wrote an add-in which I load on the Workbook_Open event, and close on the
> > Workbook_BeforeClose event.
> >
> > I just noticed that if you go to close the file, but then hit Cancel, so
> > you're still in the file, my Add-In has been unloaded.
> >
> > This means that the BeforeClose event is firing prior to the pressing of the
> > Cancel button, which then keeps the workbook open.
> >
> > It's not a huge deal, but, someone will likely see this as a bug, if I leave
> > it this way. Ideas on how to trap the press of the Cancel button, and reload
> > the Add-In?
> >
> > I'm not sure that's most efficient, though... I'd rather not unload the
> > Add-In until the workbook is really going to close.
> >
> > Ideas?
> > Thanks.

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      26th Sep 2008
Personally I haven't tried it, but it might be problematic. You are trying to
close XL but you are saying do not close the addin. That is what cancel does
is it allows you to end the close process. It has nothing to do with finding
out if the user hit cancel or not.

When you install an addin the install event fires and I use that to create
menu options and such. I use the uninstall to remove the menu options. While
I do use the open event to initialize variables and objects I do not use the
close event to destroy them. I just let them get destroyed when XL closes. My
uninstall also destroys them.
--
HTH...

Jim Thomlinson


"mark" wrote:

> with you part way...
>
> but, on the test I just did, the Add-In doesn't uninstall when I close the
> workbook, which is what I want.
>
> So, tracking back, I still need something to fire the Add-In Uninstall Event.
>
> I noticed that the BeforeClose had a parameter (Cancel as Boolean) that I
> wasn't using. I could trap that.
>
> Or did I miss something in what you said?
>
>
> "Jim Thomlinson" wrote:
>
> > Instead of using the on open and on close events try using the Addin Install
> > and Addin Unistall events. They do not get fired on Cancel. Note that your
> > addin would not be alone in this category. There are lots of addins that fall
> > into this trap. Even commercial product such as Oracle's (Hyperion) Essbase
> > addin unloads in this manner.
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "mark" wrote:
> >
> > > I wrote an add-in which I load on the Workbook_Open event, and close on the
> > > Workbook_BeforeClose event.
> > >
> > > I just noticed that if you go to close the file, but then hit Cancel, so
> > > you're still in the file, my Add-In has been unloaded.
> > >
> > > This means that the BeforeClose event is firing prior to the pressing of the
> > > Cancel button, which then keeps the workbook open.
> > >
> > > It's not a huge deal, but, someone will likely see this as a bug, if I leave
> > > it this way. Ideas on how to trap the press of the Cancel button, and reload
> > > the Add-In?
> > >
> > > I'm not sure that's most efficient, though... I'd rather not unload the
> > > Add-In until the workbook is really going to close.
> > >
> > > Ideas?
> > > Thanks.

 
Reply With Quote
 
mark
Guest
Posts: n/a
 
      26th Sep 2008
Sounds like we're doing some slightly different things.

My Add-In doesn't put in any new menus, just some subroutines and functions
for database access to an Oracle database.

There is a connection to the database in there, which we want to have
available when a given workbook is open, and not available when that given
workbook is not open.

You wrote:

"You are trying to close XL but you are saying do not close the addin."

It's actually sort of the opposite of that. Whether or not I'm closing
Excel, isn't the question... just the workbook. If the workbook closes,
uninstall the Add-In. If the workbook opens, install the Add-In.... is what
is wanted (partially by management).


 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      29th Sep 2008
The before close event fires prior to the dialog that allows the user to
cancel. So it doesn not containg the user repsonse. Rather it allows you to
cancel the closing of the addin. If you cancel the closing and the user
choose to continue with exiting XL it may cause an issue. It may not but it
is something to watch out for. What are you using the before close event
for???
--
HTH...

Jim Thomlinson


"mark" wrote:

> Sounds like we're doing some slightly different things.
>
> My Add-In doesn't put in any new menus, just some subroutines and functions
> for database access to an Oracle database.
>
> There is a connection to the database in there, which we want to have
> available when a given workbook is open, and not available when that given
> workbook is not open.
>
> You wrote:
>
> "You are trying to close XL but you are saying do not close the addin."
>
> It's actually sort of the opposite of that. Whether or not I'm closing
> Excel, isn't the question... just the workbook. If the workbook closes,
> uninstall the Add-In. If the workbook opens, install the Add-In.... is what
> is wanted (partially by management).
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Email will not close during close event tsshaw78 General Software 0 4th Jun 2009 08:52 PM
Before Close Event Hide all Worksheets then Close Application RyanH Microsoft Excel Programming 0 24th Jan 2008 03:15 PM
Access Close Event: What Order Do Forms Close? misseill Microsoft Access 1 14th May 2007 10:03 PM
[C++] how to use Close Event with void Close( BOOL * Cancel) cyan21 Microsoft Outlook Program Addins 0 12th Jul 2005 12:39 PM
Save and Close does not fire Inspector.Close event Roderic Microsoft Outlook Program Addins 3 8th Oct 2004 04:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:58 AM.