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,
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
Call the Function in the Form_Load Event of a form as follows:
Private Sub Form_Load()