我正在尝试在Userform
中运行方法时将其最小化。我的方法的功能是如此之大,以至于它可以长时间运行。我想最小化UserForm
,以便我可以处理其他一些excel工作表,然后在此运行期间返回到UserForm
(或将其还原)。
当UserForm
运行时,它不允许访问其任何组件(因此,即使我添加了最小化按钮,它也没有用)。我可以访问其他专家并进行处理,因为我将Userform
设置为vbmodeless
,但是我的要求是将userform
最小化,现在我将UserForm
拖到屏幕的末尾以查看其他文件。
最佳答案
为什么不向您的用户表单添加最小化/最大化;)
这是我数据库中的内容(不是我的代码)。将此粘贴到用户表单中
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const GWL_STYLE As Long = (-16)
Private Const WS_SYSMENU As Long = &H80000
Private Const SW_SHOWMAXIMIZED = 3
Private Sub UserForm_Activate()
Dim Ret As Long, styl As Long
Ret = FindWindow("ThunderDFrame", Me.Caption)
styl = GetWindowLong(Ret, GWL_STYLE)
styl = styl Or WS_SYSMENU
styl = styl Or WS_MINIMIZEBOX
styl = styl Or WS_MAXIMIZEBOX
SetWindowLong Ret, GWL_STYLE, (styl)
DrawMenuBar Ret
End Sub
屏幕截图