ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disabling the red X on the top right of a form. (https://www.excelbanter.com/excel-programming/339030-disabling-red-x-top-right-form.html)

jlroper[_5_]

Disabling the red X on the top right of a form.
 

Does anyone know how to disable the red X on the top right of a form
:confused

--
jlrope
-----------------------------------------------------------------------
jlroper's Profile: http://www.excelforum.com/member.php...fo&userid=2670
View this thread: http://www.excelforum.com/showthread.php?threadid=40142


PraxisPete

Disabling the red X on the top right of a form.
 
I am no expert but try this in the code module for the UserForm
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub

"jlroper" wrote:


Does anyone know how to disable the red X on the top right of a form?
:confused:


--
jlroper
------------------------------------------------------------------------
jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
View this thread: http://www.excelforum.com/showthread...hreadid=401423



dominicb[_112_]

Disabling the red X on the top right of a form.
 

Good afternoon jlroper

It can be done, but only through using Windows API calls. It als
makes a difference what version of Excel you are using, but the cod
below should handle this for you. Put this code in your main module:

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alia
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alia
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVa
dwNewLong As Long) As Long

Sub HideX(UForm As Object)
Dim Win As Long, WinStyle As Long
If Val(Application.Version) = 9 Then
Win = FindWindow("ThunderDFrame", UForm.Caption)
Else
Win = FindWindow("ThunderXFrame", UForm.Caption)
End If
WinStyle = GetWindowLong(Win, -16)
SetWindowLong Win, -16, WinStyle And Not &H80000
End Sub

Sub DisplayForm()
UserForm1.Show
End Sub

and in your userform module put this in your initialization routine:

HideX UserForm1

Just remember to include a button in there for the user to cancel...!

HTH

Dominic

--
dominic
-----------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893
View this thread: http://www.excelforum.com/showthread.php?threadid=40142


Jon Peltier[_9_]

Disabling the red X on the top right of a form.
 
Since the user is generally trying to cancel the userform, I execute the
cancel button code from this event. It keeps the user's annoyance level
down.

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
CancelButton_Click
End If
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


PraxisPete wrote:
I am no expert but try this in the code module for the UserForm
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub

"jlroper" wrote:


Does anyone know how to disable the red X on the top right of a form?
:confused:


--
jlroper
------------------------------------------------------------------------
jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
View this thread: http://www.excelforum.com/showthread...hreadid=401423



NickHK

Disabling the red X on the top right of a form.
 
Jon,
Yes, I would be annoyed if the form did not act the way it (Windows) is
designed to work.
If it does not function, then it should not be there.

NickHK

"Jon Peltier" wrote in message
...
Since the user is generally trying to cancel the userform, I execute the
cancel button code from this event. It keeps the user's annoyance level
down.

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
CancelButton_Click
End If
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


PraxisPete wrote:
I am no expert but try this in the code module for the UserForm
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub

"jlroper" wrote:


Does anyone know how to disable the red X on the top right of a form?
:confused:


--
jlroper
------------------------------------------------------------------------
jlroper's Profile:

http://www.excelforum.com/member.php...o&userid=26709
View this thread:

http://www.excelforum.com/showthread...hreadid=401423





jlroper[_6_]

Disabling the red X on the top right of a form.
 
Dominicb,

When I put in the code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long


I received an error that said:
Compile error:
Expected: line number or label or statement or end of statement
(the third line above was red also).

Do you know how to get around that (is that the version issue you were
speaking about?)

Thanks.

"dominicb" wrote:


Good afternoon jlroper

It can be done, but only through using Windows API calls. It also
makes a difference what version of Excel you are using, but the code
below should handle this for you. Put this code in your main module:

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
dwNewLong As Long) As Long

Sub HideX(UForm As Object)
Dim Win As Long, WinStyle As Long
If Val(Application.Version) = 9 Then
Win = FindWindow("ThunderDFrame", UForm.Caption)
Else
Win = FindWindow("ThunderXFrame", UForm.Caption)
End If
WinStyle = GetWindowLong(Win, -16)
SetWindowLong Win, -16, WinStyle And Not &H80000
End Sub

Sub DisplayForm()
UserForm1.Show
End Sub

and in your userform module put this in your initialization routine:

HideX UserForm1

Just remember to include a button in there for the user to cancel...!

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=401423



jlroper[_6_]

Disabling the red X on the top right of a form.
 
Hey Mr. Peltier,

My form is automatically loaded when I click on the icon, is there a way to
incorporate that code you gave me within the "auto_load" module or area
(forgive me if I'm incorrect in stating that it's a module if it is not)?

Thanks.


"Jon Peltier" wrote:

Since the user is generally trying to cancel the userform, I execute the
cancel button code from this event. It keeps the user's annoyance level
down.

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
CancelButton_Click
End If
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


PraxisPete wrote:
I am no expert but try this in the code module for the UserForm
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub

"jlroper" wrote:


Does anyone know how to disable the red X on the top right of a form?
:confused:


--
jlroper
------------------------------------------------------------------------
jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
View this thread: http://www.excelforum.com/showthread...hreadid=401423




jlroper[_7_]

Disabling the red X on the top right of a form.
 

That worked great thanks Mr. Peltier! :)


--
jlroper
------------------------------------------------------------------------
jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
View this thread: http://www.excelforum.com/showthread...hreadid=401423


dominicb[_117_]

Disabling the red X on the top right of a form.
 

Hi jlroper

Sorry for the delay in my reply - only just spotted your question from
yesterday. You will probably find that the code you are copying is
breaking at a certain points where Excel is expecting them to continue
- probably due to the screen width on the forum you are viewing from.
I've put together a small example file, just so you can see how it
should look and work.

HTH

DominicB


+-------------------------------------------------------------------+
|Filename: Book1.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3793 |
+-------------------------------------------------------------------+

--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=401423



All times are GMT +1. The time now is 10:59 AM.

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