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
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