如何从excel userform中删除close(X)选项?我得到了已经讨论过的以下链接。 http://www.excelforum.com/excel-programming-vba-macros/694008-remove-user-form-borders.html
但是我得到了他们给的东西,请帮助我......
答案 0 :(得分:6)
首先:确保至少包含一种明显的方法来关闭表单!!
点击关闭后,我不会用最后一个用户的消息框打扰他,而是完全隐藏关闭:
'//Find the userform'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 GWL_STYLE = -16
Const WS_SYSMENU = &H80000
Private Sub UserForm_Initialize()
Dim hWnd As Long, lStyle As Long
If Val(Application.Version) >= 9 Then
hWnd = FindWindow("ThunderDFrame", Me.Caption)
Else
hWnd = FindWindow("ThunderXFrame", Me.Caption)
End If
'//Get the current window style and turn off the Close button
lStyle = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong hWnd, GWL_STYLE, (lStyle And Not WS_SYSMENU)
End Sub
如果你想通过ALT-F4阻止关闭,那么也可以使用它:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub