Disable close button of Modeless Userform

R

RB Smissaert

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
 
R

RB Smissaert

Solved this one. Not sure what did the trick, probably putting DoEvents in
just the right place.

RBS
 
R

RB Smissaert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top