gpt4 book ai didi

excel - 如何从 Excel 用户窗体中删除 close(x) 选项?

转载 作者:行者123 更新时间:2023-12-03 00:32:10 27 4
gpt4 key购买 nike

如何从 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

关于excel - 如何从 Excel 用户窗体中删除 close(x) 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150186/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com