Results 1 to 2 of 2

Thread: VBA close button

  1. #1
    Junior Member
    Join Date
    Aug 2004

    Question VBA close button

    Could sum1 please tell me how I can disable or hide the close (x) button th@ is present in title bar @ the top right of a vba form.

    I have created the form using the VB editor in MS Excel. I need to be able to do this as I want the form to act as a password input form for the MS Excel spreadsheet which I am creating.

    I am sorry to ask such a stupid question, as I do know how to program in Visual Basic (6 and .NET) and I have done this be4 in VBA, but th@ was about 2 years ago, so stupid me has forgot how 2 do it.

    Thanx in advance,

  2. #2
    In And Above Man Black Cluster's Avatar
    Join Date
    Feb 2005
    This is how to DISABLE it,,,

    Put this in a module in the General Declarations of a Module

    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
    Public Const MF_BYPOSITION = &H400&
    Put this in a Module so that it can be accessed by different Forms
    Public Sub DisableCloseWindowButton(frm As Form)
        Dim hSysMenu As Long
        'Get the handle to this windows system menu
        hSysMenu = GetSystemMenu(frm.hwnd, 0)
        'Remove the Close menu item This will also disable the close button
        RemoveMenu hSysMenu, 6, MF_BYPOSITION
        'Lastly, we remove the seperator bar
        RemoveMenu hSysMenu, 5, MF_BYPOSITION
    End Sub
    Call the Function in the Form_Load Event of a form as follows:
    Private Sub Form_Load()
        DisableCloseWindowButton Me
    End Sub
    \"The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts\".....Spaf
    Everytime I learn a new thing, I discover how ignorant I am.- ... Black Cluster

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts