Full Version: Cancel all closes except with user forms button close
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
randyzapata
I am using the following to prevent a user from closing a form but I also want prevent a user from saving or closing excel except if they use my user form buttons. Is this possible?

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Application.DisplayAlerts = True
MsgBox "Sorry, you may not close the form like that!"
Cancel = True
Application.DisplayAlerts = False
End If
End Sub
KingMartin
Hi Randy,

showing the form as modal,

Userform1.Show vbModal

could help.

Martin
randyzapata
but how do I disable the user from saving or closing excel when I close or hide the user form
KingMartin
You'll need API calls for true disabling of the close button in the application menu.

I attached an example of a pure VBA approach, see if it helps...

Martin
randyzapata
That was just what I was trying to do frown.gif

Thanks again
KingMartin
Glad to help,

you're welcome
frown.gif
Martin
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.