如何从 excel 用户表单中删除 close(X) 选项?我得到了已经讨论过的以下链接。 http://www.excelforum.com/excel-programming-vba-macros/694008-remove-user-form-borders.html
但是我得到了他们给的东西,请帮助我....
如何从 excel 用户表单中删除 close(X) 选项?我得到了已经讨论过的以下链接。 http://www.excelforum.com/excel-programming-vba-macros/694008-remove-user-form-borders.html
但是我得到了他们给的东西,请帮助我....
首先:确保您至少包含一种明显的关闭表单的方法!
我不会在点击关闭后用消息框打扰最终用户,而是完全隐藏关闭:
'//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