Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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?



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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default 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?



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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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?



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

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

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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?



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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling macros EllenM Excel Discussion (Misc queries) 1 February 26th 08 04:57 PM
disabling CUT function Keef Excel Discussion (Misc queries) 2 January 23rd 05 12:17 AM
disabling cells lak Excel Programming 6 May 17th 04 11:00 PM
Disabling Alt+F11 richard_b2004 Excel Programming 3 May 17th 04 06:32 PM
Auto_Open disabling Tritan Excel Programming 6 July 22nd 03 11:48 AM


All times are GMT +1. The time now is 11:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"