call the following routine with
HideCloseButton <formObject>
insert into a module:
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'Find the Dialog's Window
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Get the current window style
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
'Set the new window style
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const WS_SYSMENU = &H80000
Const GWL_STYLE = (-16)
'Routine to hide the close button on a userform or dialogsheet
' oDialog is either the Userform or Dialog object
Sub HideCloseButton(oDialog As Object)
Dim hWnd As Long, lStyle As Long
'Were we given a userform or a dialog sheet
If TypeName(oDialog) = "DialogSheet" Then
'We had a dialog sheet. Note that pressing Escape still closes the dialog
Select Case Int(Val(Application.Version))
Case 5 'Doesn't work in Excel 5 - we only have 32-bit DLL calls here
Case 7 'Excel 95
hWnd = FindWindow("bosa_sdm_XL", oDialog.DialogFrame.Caption) 'DialogSheet
Case 8 'Excel 97
hWnd = FindWindow("bosa_sdm_XL8", oDialog.DialogFrame.Caption) 'DialogSheet
Case 9 'Excel 2000
hWnd = FindWindow("bosa_sdm_XL9", oDialog.DialogFrame.Caption) 'DialogSheet
End Select
Else
'We had a userform
Select Case Int(Val(Application.Version))
Case 8 'Excel 97
hWnd = FindWindow("ThunderXFrame", oDialog.Caption) 'UserForm
Case 9 'Excel 2000
hWnd = FindWindow("ThunderDFrame", oDialog.Caption) 'UserForm
End Select
End If
'Get the current window style
lStyle = GetWindowLong(hWnd, GWL_STYLE)
'Turn off the System Menu bit
SetWindowLong hWnd, GWL_STYLE, lStyle And Not WS_SYSMENU
End Sub
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ide