ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Removing The Quit/X Button On An Userform (https://www.excelbanter.com/excel-programming/421475-removing-quit-x-button-userform.html)

Hennie Neuhoff

Removing The Quit/X Button On An Userform
 
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

FSt1

Removing The Quit/X Button On An Userform
 
hi
not sure if you have remove it. it's to my understanding that it's sort of
built in to all forms.
but... you can disable it.
see this sites for ideas.
http://www.vbaexpress.com/kb/getarticle.php?kb_id=164
http://j-walk.com/ss/Excel/tips/tip80.htm

regards
FSt1

"Hennie Neuhoff" wrote:

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


Peter T

Removing The Quit/X Button On An Userform
 
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




John

Removing The Quit/X Button On An Userform
 
Peter's approach is the one to genearlly follow but if you want to know how
to do it, Stephen Bullen has an example file you can download.
http://www.oaltd.co.uk/Excel/Default.htm
Look for NoCloseButton.ZIP file in list.
--
jb


"Hennie Neuhoff" wrote:

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


Jon Peltier

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






Peter T

Removing The Quit/X Button On An Userform
 
Hi Jon,

The purpose of the little demo was to show the QueryClose event to the OP
with a view to rethinking the objective of removing the little x. It showed
how pressing the little x, pressing Esc, or the cancel button can all lead
to the same "clear up" routine. The additional prompt was merely to
demonstrate options.

Having said that, sometimes the user's intensions of closing with the little
x can be ambiguous, particularly when OK and Cancel buttons both exist on
the form.

Obviously it means close the form but does it mean keep and apply all the
actions, or do nothing and/or undo any changes. Many users do not know the
convention that the little x is equivalent to cancel (and possibly undo
changes).

When unclear, and particularly if the user is about to discard a lot of
work, it's not uncommon to seek confirmation from a small prompt.

Regards,
Peter T

"Jon Peltier" wrote in message
...
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








Chip Pearson

Removing The Quit/X Button On An Userform
 
You can remove that button by calling a few API calls. Download the
file at http://www.cpearson.com/Excel/formcontrol.aspx , copy the
module "modFormControl" in to your project. Depending on where you put
the code, you may have to change some constants' scope from Private to
Public. Then call the procedure name "ShowCloseButton". Despite its
name, it can both hide and show the close button on a form:

ShowCloseButton UF:=UserForm1, HideButton:=True

The web page shows quite a few cool things you can do with user forms
via the Windows API libraries.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Wed, 17 Dec 2008 20:28:00 -0800, Hennie Neuhoff
wrote:

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


Jon Peltier

Removing The Quit/X Button On An Userform
 
It's common enough that the little red X means "Cancel" so I don't bother
with a dialog (nor when the user clicks the Cancel button). But if you have
dumb users <g, be my guest.

I think my point was that it was probably a good idea to funnel the X click
through the Cancel button click. Minimize redundant code paths and all.

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


"Peter T" <peter_t@discussions wrote in message
...
Hi Jon,

The purpose of the little demo was to show the QueryClose event to the OP
with a view to rethinking the objective of removing the little x. It
showed how pressing the little x, pressing Esc, or the cancel button can
all lead to the same "clear up" routine. The additional prompt was merely
to demonstrate options.

Having said that, sometimes the user's intensions of closing with the
little x can be ambiguous, particularly when OK and Cancel buttons both
exist on the form.

Obviously it means close the form but does it mean keep and apply all the
actions, or do nothing and/or undo any changes. Many users do not know
the convention that the little x is equivalent to cancel (and possibly
undo changes).

When unclear, and particularly if the user is about to discard a lot of
work, it's not uncommon to seek confirmation from a small prompt.

Regards,
Peter T

"Jon Peltier" wrote in message
...
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










All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com