【发布时间】:2013-02-15 16:53:32
【问题描述】:
我创建了一个用户窗体来在宏仍在导入工作表时显示进度条
问题是用户可以按下红色的 [X] 按钮,该按钮将关闭并中断已完成的处理。
有没有办法隐藏这个厄运的红色按钮,这样潜在用户在它运行时就不会有任何令人困惑的按钮可以点击。
编辑:
我试过了
'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
我在 userform_initialize 上使用了这个
Dim hWnd As Long, lStyle As Long
'Which type of userform
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)
我收到此错误消息
此代码取自 here。我不知道我做错了什么,我已经删除了 cmets。这是我发现的最简单的代码,所以我想将它集成到我的用户表单中。任何帮助表示赞赏。
【问题讨论】:
-
这个问题的答案是我的热门搜索结果。你有没有尝试过?
-
更新了更多信息
-
如果您打算这样做,您能否澄清并将“禁用”一词更改为“隐藏和禁用”?禁用该功能相对简单。隐藏它似乎不是。
-
@forums:你试过下面的代码了吗?
-
要解决您在屏幕截图中显示的问题:将所有 API 声明移至模块顶部!