Results 1 to 2 of 2
  1. #1
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    San Jose, California, USA
    Thanked 0 Times in 0 Posts

    Cancel the Close dialog (Excel 97/2000, SR2)

    How can I detect that the user pressed Cancel from the Save dialog (it says "Do you want to save the changes...")? I have code in workbook_deactive(), workbook_beforeclose() and workbook_beforesave() that does clean up. If the user ends up canceling the close action, I need to restore some of the things I removed in the _beforeclose() event. I can't find any event that tells me the user canceled. There has to be something that I can use, but I'm not seeing the solution at the moment. Right now I added some code in a sheet_activate event which detects if the "clean up" has been done (as consequence of closing workbook). If it has then it restores the removed items. This solution isn't very good since it relies on the user activating that sheet before the code runs, of course.

    Deb <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Dublin, Ireland, Republic of
    Thanked 0 Times in 0 Posts

    Re: Cancel the Close dialog (Excel 97/2000, SR2)

    You could include code in your workbook before close to intercept the Save Dialog, and ask th euser yourself wiyth a message box. Something like <pre> If Not Thisworkbook.Saved then
    Action = MsgBox("Save before closing ?", vbQuestion + vbYesNoCancel)..</pre>

    and use a select case or nested If thens to take action based on the value of Action, abYes, vbNo or VbCancel. (If vbCancel set the Cancel property to True, if vbNo then set the Saved Property to True).

    Whatever clean up you intend could be carried ot if vbYes or vbNo, but not if vbCancel.

    Andrew C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts