View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy[_8_] Doug Glancy[_8_] is offline
external usenet poster
 
Posts: 63
Default How can I detect that the user canceled a close?

TomThumb,

If I understand correctly now, you've got an addin that creates a toolbar
when the addin Opens and deletes it at the addin's BeforeClose event.

If this is correct, I think you can just create the toolbar with
Temporary:=True and forget about deleting it when the addin closes. The
only time the addin should close is if it's unchecked in ToolsAddins or
when Excel closes. This way the toolbar will be automatically deleted when
Excel closes. You would also want to add the delete toolbar code to the
AddinUninstall event, so that it would be deleted if the addin is unchecked
in the ToolsAddin menu.

I'm probably missing something, but thought I'd try one more time to help,

Doug

"TomThumb" wrote in message
...
Doug & Peter T:

The WorkbookDeactivate event procedure did not remove the toolbar. The
Ontime works, but is problematic as I did get an error message once.

I need to get closer to close than WorkbookBeforeClose.

--
TomThumb


"Doug Glancy" wrote:

Peter T,

Then why is the user being prompted to save changes? I thought it was
the
situation where the toolbar is created at workbook open and deleted at
close.

Doug

"Peter T" <peter_t@discussions wrote in message
...
Hi Doug,

The Deactivate & Activate events are not triggered in an addin, which
as I
understand is what the OP wants to cater for.

Regards,
Peter T

"Doug Glancy" wrote in message
...
TomThumb,

Instead of the Open and BeforeClose events, look at using Activate and
Deactivate instead. When a workbook closes the Deactivate event fires
after
the BeforeClose and the Cancel message. Also, then your toolbar will
be
deleted when you switch to another workbook, which I'm guessing is
also
what
you want.

hth,

Doug

"TomThumb" wrote in message
...
Peter T:

Thank you for responding to my plea for help. I should have spelled
out
what I have in mind:

I have an Add-In Toolbar that I delete in my WorkBookBeforeClose
event
procedure. But when the user closes and then clicks "Cancel" when
asked
to
Save, the Close is terminated and the toolbar is gone. I want to
restore
that toolbar, or not delete it in the first place.

Can I somehow get a boolean from WorkbookBeforeSave?
--
TomThumb


"Peter T" wrote:

"user canceled a close" - do you mean if user cancels Excel-quit or
merely
while doing file-close, that might be relevant depending on your
ultimate
objective. However in either case there is no direct method to
return
your
boolean if user cancelled close during the 'save unsaved file(s)
prompt'.

I assume you want to know so as to determine whether or not to run
your
close event code. One workaround is to run the close event as
normal,
but
also call a routine with the OnTime method to restore as-was. Eg
with
an
addins, might want to remove all menus as normal in the close event
then
put
them back again a few seconds later if the workbook is still open.

A different approach is to use a Com-addin. This has the advantage
that
its
close event only fires when Excel really is about to quit and won't
be
cancelled. There are various ways to get the CAI to call a routine
in
the
wb
to run close code 'only' if Excel and hence the file is about to
close.
I
believe Chip Pearson has made available on his site a CAI to do
that,
which
makes use of the 'hidden namespace'. I have a CAI that does similar
but
with
a different approach (doesn't use the namespace) if interested.

Regards,
Peter T

"TomThumb" wrote in message
...
That is all I need to know: Just how can I obtain what is
probably
a
boolean
value telling me the user canceled a close.
--
TomThumb