Results 1 to 3 of 3

Thread: minimizing a form *RESOLVED*

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8

    minimizing a form *RESOLVED*

    In vba for excel97 I designed a form, but when I open the form I can't minimize it. Does someone know if there's code so the form can be minimized?
    Last edited by marinus; May 7th, 2003 at 04:07 AM.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    VBA extends the capabilities of an existing application. The UserForm is designed to be a custom dialogue box. It minimizes with the application. Like any other dialogue box, it pops up, allows the user to enter data or make some choices, then closes and returns functionality to the application.

    Minimizing a UserForm can cause problems because users don't generally expect dialogue boxes to minimize and the minimized forms can hide without the user remembering that they are there. A better solution might be to pass all data collected from the UserForm to global variables so that the form can retrieve, display, and update the variables as the user opens and closes the UserForm.

    If you are hell-bent on minimizing the UserForm, you can do so through API. Make sure that you set the UserForm property ShowModal to False, otherwise the user will not be able to do anything in Excel until the UserForm is closed.

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    5.     (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    6.  
    7. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    8.     (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    9.  
    10. Private Const WS_MINIMIZEBOX = &H20000
    11. Private Const GWL_STYLE = (-16)
    12.  
    13. Private Sub AddMinBox()
    14.  
    15.     ' Add minimize button to UserForm.
    16.  
    17.     Dim hWnd As Long
    18.  
    19.     Select Case Int(Val(Application.Version))
    20.         Case 8      ' Office 97.
    21.             hWnd = FindWindow("ThunderXFrame", vbNullString)
    22.         Case 9, 10  ' Office 2000, XP
    23.             hWnd = FindWindow("ThunderDFrame", vbNullString)
    24.     End Select
    25.    
    26.     SetWindowLong hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) Or WS_MINIMIZEBOX
    27.    
    28. End Sub
    29.  
    30. Private Sub UserForm_Initialize()
    31.     AddMinBox
    32. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8
    It works deliciously

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width