'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 Else 'Excel 2000 and newer
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 Else 'Excel 2000 and newer
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
کامنت