在其中的宏运行时最小化UserForm

时间:2013-12-12 21:53:12

标签: excel excel-vba vba

我正在尝试在其中运行方法时最小化Userform。我的方法中的功能如此之大,以至于它运行了很长时间。我想最小化UserForm,以便我可以处理其他一些Excel工作表,然后在此次运行期间返回UserForm(或恢复它)。

UserForm正在运行时,它不允许访问其任何组件(因此,即使我添加了最小化按钮,也没有用)。我可以访问其他excel并使用它们,因为我已将Userform设为vbmodeless,但我的要求userform应该最小化,现在我拖动UserForm到{{1}}屏幕的末尾可以轻松查看其他文件。

1 个答案:

答案 0 :(得分:4)

为什么不为用户表单添加最小化/最大化;)

以下是我的数据库中的内容(不是我的代码)。将其粘贴到用户表单

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

<强>截图

enter image description here