gpt4 book ai didi

excel - 隐藏 Excel VBA 用户窗体上进度条的关闭 [X] 按钮

转载 作者:行者123 更新时间:2023-12-01 18:41:32 24 4
gpt4 key购买 nike

我创建了一个用户窗体,以在宏仍在导入工作表时显示进度条 enter image description here

问题是用户可以按下红色的[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)

我收到此错误消息 enter image description here

此代码取自here 。我不知道我做错了什么,我已经删除了评论。这是我发现的最简单的代码,因此我想将其集成到我的用户表单中。如有任何帮助,我们将不胜感激。

最佳答案

下面是一个例程,您可以这样调用:

subRemoveCloseButton MyForm

或者从您的表单中:

subRemoveCloseButton Me 

这是您需要的代码:

Private Const mcGWL_STYLE = (-16)
Private Const mcWS_SYSMENU = &H80000

'Windows API calls to handle windows
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#Else
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If

#If VBA7 Then
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
#Else
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
#End If

#If VBA7 Then
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#Else
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If


Public Sub subRemoveCloseButton(frm As Object)
Dim lngStyle As Long
Dim lngHWnd As Long

lngHWnd = FindWindow(vbNullString, frm.Caption)
lngStyle = GetWindowLong(lngHWnd, mcGWL_STYLE)

If lngStyle And mcWS_SYSMENU > 0 Then
SetWindowLong lngHWnd, mcGWL_STYLE, (lngStyle And Not mcWS_SYSMENU)
End If

End Sub

关于excel - 隐藏 Excel VBA 用户窗体上进度条的关闭 [X] 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15153491/

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