Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default form closing with the X


Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile: http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default form closing with the X

You don't need to remove it, you can trap it. Look up the QueryClose Event
in help.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"raw" wrote in message
...

Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile:

http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default form closing with the X

I find it causes less confustion with the user to have the X button disabled
by the Windows API:


In a normal module have this:

Option Explicit
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Public Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) _
As Long

Sub DisableCloseButton(hwnd As Long)

Dim hMenu As Long
Dim menuItemCount As Long

hMenu = GetSystemMenu(hwnd, 0)

If hMenu Then
menuItemCount = GetMenuItemCount(hMenu)
RemoveMenu hMenu, _
menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION
DrawMenuBar hwnd
End If

End Sub

Sub LoadForm()

Load UserForm1
UserForm1.Show

End Sub


In the form code have this:

Option Explicit

Private Sub UserForm_Activate()
DisableCloseButton GetActiveWindow()
End Sub


RBS


"raw" wrote in message
...

Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile:
http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375


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
Closing a Form Mike Excel Discussion (Misc queries) 2 March 14th 06 01:09 PM
Closing Form problem Jos Vens[_2_] Excel Programming 3 April 7th 05 02:06 AM
HELP! - Closing form Alex J Excel Programming 1 September 17th 04 01:37 AM
HELP! - Closing form Norman Jones Excel Programming 0 September 16th 04 03:21 AM
need form to initialize without closing bruce forster Excel Programming 2 April 21st 04 11:57 PM


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

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"