Results 1 to 3 of 3

Thread: [RESOLVED] Msgbox before exit

  1. #1

    Thread Starter
    Addicted Member Fonty's Avatar
    Join Date
    May 2006
    Location
    New York
    Posts
    173

    Resolved [RESOLVED] Msgbox before exit

    Is it possible pop up a msgbox before closing a userform by clicking the X button, so that you have the option to cancel this action?
    Last edited by Fonty; May 30th, 2007 at 09:17 AM.

  2. #2
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Re: Msgbox before exit

    You could always disable it and then create you're own close button on your form that you can freely handle...

    Click here for link for code to disable the 'x' close button

  3. #3
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Msgbox before exit

    Code:
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If MsgBox("Really close?", vbYesNo + vbQuestion, "Close Userform") = vbNo Then
        Cancel = True
    End If
    End Sub
    
    'excel 2007
    I didn't try all options but test the CloseMode param for the following values:
    Code:
    vbFormControlMenu -- 0 -- The user chose the Close command from the Control menu on the form. 
    vbFormCode  -- 1 -- The Unload statement is invoked from code. 
    vbAppWindows -- 2 -- The current Microsoft Windows operating environment session is ending. 
    vbAppTaskManager -- 3 -- The Windows Task Manager is closing the application.
    Last edited by kewakl; May 30th, 2007 at 05:00 AM. Reason: xl version
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

Posting Permissions

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



Click Here to Expand Forum to Full Width