PC Review


Reply
Thread Tools Rate Thread

Disabling the Red X in Excel

 
 
=?Utf-8?B?YmVnaW5uZXIgaGVyZQ==?=
Guest
Posts: n/a
 
      30th Oct 2006
I'm trying to find the coding to disable the red 'X' in the right hand corner
of any Excel worksheet. I know what the code is for a form, but can't find
the code for the worksheet.

The code I'm using for my form is the following:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button !!"
End If
End Sub


Any help would be appreciated.

Steve

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SGFsaW0=?=
Guest
Posts: n/a
 
      31st Oct 2006
Hi,

you can disabled "X" controlbox by API calls like:
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function DeleteMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As
Long

Private Const SC_CLOSE As Long = &HF060 'Close "x" box

Sub DisabledX()
Dim Hwndx As Long, xBox As Long

If Val(Application.Version) <= 9 Then
Hwndx = FindWindow("XLMAIN", Application.Caption) 'xl2000 and earlier
Else
Hwndx = Application.hwnd 'xl2002 and later
End If

Hwndx = FindWindowEx(Hwndx, 0, "XLDESK", vbNullString)
Hwndx = FindWindowEx(Hwndx, 0, "EXCEL7", ActiveWindow.Caption)

xBox = GetSystemMenu(Hwndx, 0)

DeleteMenu xBox, SC_CLOSE, 0&
'Doesnt work unless you change the window state of worksheet/book to
restore

End Sub


--

Regards,

Halim


"beginner here" wrote:

> I'm trying to find the coding to disable the red 'X' in the right hand corner
> of any Excel worksheet. I know what the code is for a form, but can't find
> the code for the worksheet.
>
> The code I'm using for my form is the following:
>
> Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
> If CloseMode = vbFormControlMenu Then
> Cancel = True
> MsgBox "Please use the button !!"
> End If
> End Sub
>
>
> Any help would be appreciated.
>
> Steve
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Oct 2006
Just a curiosity question...

Why do you want to stop the user from using the X button? If there's some code
in the Cancel button that needs to be run, couldn't your userform_queryclose
procedure call that cancel button's procedure?



beginner here wrote:
>
> I'm trying to find the coding to disable the red 'X' in the right hand corner
> of any Excel worksheet. I know what the code is for a form, but can't find
> the code for the worksheet.
>
> The code I'm using for my form is the following:
>
> Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
> If CloseMode = vbFormControlMenu Then
> Cancel = True
> MsgBox "Please use the button !!"
> End If
> End Sub
>
> Any help would be appreciated.
>
> Steve


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?YmVnaW5uZXIgaGVyZQ==?=
Guest
Posts: n/a
 
      31st Oct 2006
Becasue I have reduced the size of the worksheet to match my userform size.
And by clicking on the red X to close this workbook the next time they open
Excel, the book1 sheet will come up in the same size. So I want them to have
click on the close button to return to the max size.

Steve Martin

"Dave Peterson" wrote:

> Just a curiosity question...
>
> Why do you want to stop the user from using the X button? If there's some code
> in the Cancel button that needs to be run, couldn't your userform_queryclose
> procedure call that cancel button's procedure?
>
>
>
> beginner here wrote:
> >
> > I'm trying to find the coding to disable the red 'X' in the right hand corner
> > of any Excel worksheet. I know what the code is for a form, but can't find
> > the code for the worksheet.
> >
> > The code I'm using for my form is the following:
> >
> > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
> > If CloseMode = vbFormControlMenu Then
> > Cancel = True
> > MsgBox "Please use the button !!"
> > End If
> > End Sub
> >
> > Any help would be appreciated.
> >
> > Steve

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
disabling excel 2007 =?Utf-8?B?THlubks=?= Microsoft Excel Misc 3 15th Jun 2007 10:03 PM
Re: disabling a cell in excel manohar.shankar@gmail.com Microsoft Excel Programming 0 6th Sep 2005 07:02 PM
Disabling Excel warning from VBA Sylvain Provencher Microsoft Access VBA Modules 1 8th Dec 2004 02:59 AM
Disabling Excel VBA Pop-ups... Joey Lichtenstein Microsoft Excel Programming 4 23rd Nov 2004 08:54 PM
Disabling COM Addins in Excel =?Utf-8?B?U2Ft?= Microsoft Excel Programming 0 3rd Nov 2004 10:49 PM


Features
 

Advertising
 

Newsgroups
 


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