Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2003, 11:56 AM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get rid of the close button on a form

Hi,
I am wondering how it is possible to remove the close button from a form. I want the user to choose one of two buttons I created without the possibility to close the form and not have picked

Regards
Piblon

 
Old December 16th, 2003, 12:28 PM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Removing in effect is actually just disabling it. In design view of the form open the form properties dialog and set Close Button = No. This will disable the button from there and also from the ControlBox as well. To completely remove it from the form you need to set Control Box = No.

Even with these steps there are some that know the CTRL + F4 to close the form and the ATL + F4 to close the application (not to mention the Task Manager). There is a way (via code) of restricting a form from closing until you want it closed.

Kenny Alligood
 
Old December 17th, 2003, 04:14 AM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx

I know that CTRL+F4 and ALT+F4 will close form / application, but the users for my form will probably not use this combination. Nevertheless if nothing else works, I would have to do some coding to disable those functions as well

 
Old February 16th, 2004, 04:47 PM
Authorized User
 
Join Date: Aug 2003
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
Default

I happen to read this topic while searching for something else. I have a similar situation where i had restricted the the close event through code. I could'nt find a wayout in VBA to get away with it. (The above mentioned way works fine in VB). Could you please let me know if i m missing some piece of information. I would like to know if that is possible

Ajitpal S Padda
 
Old February 17th, 2004, 05:06 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Just write this code to the Forms QueryClose method:

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

vemaju

 
Old February 20th, 2004, 10:12 AM
Authorized User
 
Join Date: Aug 2003
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am also doing the same thing...but is there a way to get away with cross icon on the right hand side top.

Thanks

Ajitpal S Padda
 
Old June 30th, 2004, 02:15 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Guys

I fund this code in a book, and it should do the trick.
The code should be placed in the userforms code module.

'Hide a UserForm's Close Button
'Find the userform's Window
Private Declare Function FindWindow Lib "user32" _
        Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long

'Get the current window style
Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long

'Set the new window style
Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long

Const GWL_STYLE = -16
Const WS_SYSMENU = &H80000

Private Sub UserForm_Initialize()
   Dim hWnd As Long, lStyle As Long

   'Which type of userform
   If Val(Application.Version) >= 9 Then
      hWnd = FindWindow("ThunderDFrame", Me.Caption)
   Else
      hWnd = FindWindow("ThunderXFrame", Me.Caption)
   End If

   'Get the current window style and turn off the Close button
   lStyle = GetWindowLong(hWnd, GWL_STYLE)
   SetWindowLong hWnd, GWL_STYLE, (lStyle And Not WS_SYSMENU)
End Sub

Cheers
Karsten






Similar Threads
Thread Thread Starter Forum Replies Last Post
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
How to get rid of everything except startup form. biglazy Access 9 March 23rd, 2006 07:33 PM
User Form: How to get rid of icon "X" Axxess Excel VBA 2 September 26th, 2005 05:34 AM
disable close button in mdi form nkramanmca VB How-To 4 January 6th, 2005 12:31 AM
how to disable a close button on VB form chanti VB How-To 2 September 30th, 2004 06:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.