View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Removing The Quit/X Button On An Userform

If the user clicks the X, he wants to close the dialog. Don't force another
dialog to ask if what he wants is really what he wants.

Run the cancel button code from the QueryClose procedure.

I have an example on this blog post:

Repurpose the Red X Close Button on a VBA UserForm
http://peltiertech.com/WordPress/200...-vba-userform/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Peter T" <peter_t@discussions wrote in message
...
Although you can disable the little x, even remove the entire caption, it
goes against convention and is not necessary. Put a button on the form,
set its Cancel property = True. Press Esc, the little x and the button

Private Sub CommandButton1_Click()
' set the cancel property of this button =True
' so it'll be called if user presses Esc
If Chow = True Then Exit Sub
Unload Me

End Sub

Private Function Chow() As Boolean

If MsgBox("Do you really want to cancel and quit ?", _
vbYesNo) < vbNo Then
' cancel code
Else
Chow = True
End If

End Function

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode < 1 Then
Cancel = Chow
End If
End Sub

Regards,
Peter T

"Hennie Neuhoff" wrote in
message ...
Hi All
Is it possible to remove the Quit/X button in the upper right corner of a
userform ?
Alternatively I've got a command button "Cancel" on the userform - if the
user do
click the Quit/ X button that the code for the cancel button applies?
I'm satisfied with the code for the cancel button, but I don't know what
steps should
be taken if the user click on the Quit/X button. [using 2003]

Thanks in advance

--
HJN