如何从Excel用户窗体中删除close(x)选项? [英] How to remove the close(x) option from excel userform?
问题描述
如何从excel用户窗体中删除close(X)选项?我得到了下面已经讨论过的链接. http://www.excelforum.com/excel-programming-vba-macros/694008-remove-user-form-borders.html
How to remove the close( X ) option from excel userform ? I got the below link which already discussed. http://www.excelforum.com/excel-programming-vba-macros/694008-remove-user-form-borders.html
但是我正在得到他们给的东西,请帮助我....
But i'm getting what they given, please help me....
推荐答案
首先:确保您至少包含一种明显的关闭表单的方法!
Firstly: make sure you include at least one obvious method to close the form!!
我不会在最终用户单击关闭后用消息框打扰他们,而是将全部关闭隐藏起来:
Instead of bothering the end user with message box's after they click close, I would hide the close altogether:
'//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进行关闭,则也可以使用它:
If you want to prevent closing via ALT-F4 then use this as well:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub
这篇关于如何从Excel用户窗体中删除close(x)选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!