Hello, I want to prevent the user from accessing the excel spreadsheets.
therefore I disable the close command (the cross in the upper right corner to close a window) and ask him to use a cancel button.

What should happen when user exits the userform:
The user will then be asked if he really wants to close or not. There he can choose between OKAY and Cancel. If he presses okay he will exit the Userform and Excel will close automatically. However, If he presses Cancel he should stay on the userform.

My problem:
When the user is asked if he "really wants to close" and presses the cancel button, excel stays open and the userform closes. BUT the userform should stay open and excel should be hidden....

Here is my code

In this workbook:

[VBA]
Private Sub Workbook_open()
Application.WindowState = xlMinimized 'user cannot see what is entered in Excel
AppActivate ("Microsoft Excel")
UserForm1.Show

End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
If (MsgBox(prompt:=" Do you really want to close?", Buttons:=vbOKCancel) = vbCancel) Then
Cancel = True
Else
Cancel = False
End If

If Cancel = False Then
Application.Quit
End If

End Sub
[/VBA]

and in the UserForm I used this code for the cancel Button:
[VBA]

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
MsgBox ("Please click the Cancel button to exit the program")
End Sub

Private Sub CMD_Cancel_Click()
ActiveWorkbook.Close savechanges = True
Unload Me
End Sub

[/VBA]