Tuesday, August 21, 2007

Disable Close Button in UserForm (VBA)

Disable Close Button in Userform (Visual Basic)

Option Explicit

'API Declarations

Const MF_BYPOSITION = &H400&


Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long

Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long




Public Sub DisableCloseWindowButton(frm As Form)

Dim hSysMenu As Long

'Get the handle of the Window
hSysMenu = GetSystemMenu(frm.hwnd, 0)

'Disable the close button of the Form
RemoveMenu hSysMenu, 6, MF_BYPOSITION

'Remove the seperator bar
RemoveMenu hSysMenu, 5, MF_BYPOSITION

End Sub

3 comments:

  1. Anonymous12:15 AM

    It Works fine.. thank you :)

    ReplyDelete
  2. Anonymous4:43 AM

    I get a Compile error: User-defined type not defined.
    The error appears to be in the line:

    Public Sub DisableCloseWindowButton(frm As Form)

    Apparently there is no such thing as a Form type...

    ReplyDelete
  3. Anonymous8:07 AM

    I receive the same message:
    User-defined type not defined.
    Public Sub DisableCloseWindowButton(frm As Form)

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.