LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Disable close button of Modeless Userform

Rob,

I could do as you suggested, but in this particular case the form is just
holding a progressbar. Apart from this it doesn't do anything else. The form
will be unloaded when the procedure is finished.
Clicking the close button just doesn't serve any purpose and I might as well
disable it. It works fine now anyhow.

RBS


"Rob Bovey" wrote in message
...
Hi RB,

Instead of going through all that trouble, why not use the QueryClose
event to diable the *action* of clicking the X-close button, rather than
disabling the button itself, i.e.

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode < vbFormCode Then Cancel = True
End Sub

Or instead (my preference), route any clicks to the X-close button through
whatever cancel procedure you've set up for your form, since this tends to
make for a more intuitive UI.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"RB Smissaert" wrote in message
...
Using Excel 2002 and 2000.
How do I disable the close button of a Modeless Userform?
I can do it with a modal userform like this:

Public Const MF_BYPOSITION = &H400
Public Const MF_REMOVE = &H1000
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Public 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

Private Sub UserForm_Activate()

DisableCloseButton GetActiveWindow()

End Sub


Sub DisableCloseButton(hWnd As Long)

Dim hMenu As Long
Dim menuItemCount As Long

hMenu = GetSystemMenu(hWnd, 0)

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

End Sub


But that doesn't work with a Modeless Userform.
Thanks for any advice.



RBS




 
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
HOW to close a userform using a button CC Excel Discussion (Misc queries) 2 October 10th 08 02:06 PM
Userform close button AOU Excel Discussion (Misc queries) 4 September 21st 07 05:56 PM
Disable Close Button dan Excel Discussion (Misc queries) 5 September 22nd 06 07:39 PM
Disable Exit button on a UserForm Noemi Excel Discussion (Misc queries) 1 September 14th 06 09:37 PM
Userform + close button Chip Smith Excel Discussion (Misc queries) 2 April 1st 06 09:35 AM


All times are GMT +1. The time now is 12:32 PM.

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

About Us

"It's about Microsoft Excel"