View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default How can I detect that the user canceled a close?

"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