+ Reply to Thread
Results 1 to 7 of 7

Minimizing a Userform

Hybrid View

  1. #1
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Minimizing a Userform

    I have code that enables me to add a minimize button to my userforms, but I don't know the code to tell the userforms to minimize. Can anyone help me with this? I would also need to know the code to make the userform reappear. Here is what I have for adding the minimize button:

    In the module window:
    Private Declare Function FindWindowA Lib "USER32" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    Private Declare Function GetWindowLongA Lib "USER32" _
    (ByVal hWnd As Long, _
    ByVal nIndex As Long) As Long
    
    Private Declare Function SetWindowLongA Lib "USER32" _
    (ByVal hWnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
    
    Sub FormatUserForm(UserFormCaption As String)
     Dim hWnd            As Long
     Dim exLong          As Long
    
        hWnd = FindWindowA(vbNullString, UserFormCaption)
        exLong = GetWindowLongA(hWnd, -16)
        If (exLong And &H20000) = 0 Then
            SetWindowLongA hWnd, -16, exLong Or &H20000
            Else
        End If
    End Sub
    In the userform code window:
    Private Sub UserForm_Initialize()
        Call FormatUserForm(UserForm1.Caption)
    End Sub
    Thanks in advance for your help!

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Minimizing a Userform

    This is a link to a userform with examples of what you can do with a userform by tapping into the Windows API. It was written by Stephen Bullen (not me) and some interesting ideas including minimizing/ maximing the userform. Hope this helps.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Minimizing a Userform

    While this is a very good source of info, I didn't find any code in there that I could use to minimize my userform. Thanks for the interesting link, though!

    Anybody else have any code that can minimize the userform, given the code I provided in the first post? Thanks

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Minimizing a Userform

    That code works fine. Is the main body of your code in Standard Module?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Minimizing a Userform

    Yes, the first set of code is in my Module1. The second set I posted is in the userform code. I may have caused confusion in my post. I know the code I posted works fine; I've used it to put the minimize button on all of the userforms in my program. I was just posting it to let everyone know what code I have to create the minimize button. The problem I'm having is that I don't know how to code commands to minimize the userforms and make them re-appear with VBA. As of right now, I have to manually minimize the userform window (it gets in the way sometimes, so having code to minimize it at certain times would be extremely helpful). Hopefully that clears things up for everyone. Thanks for looking at it!

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Minimizing a Userform

    You don't need the buttons to do that.

    Me.Hide 'hide the userform
    So if the button is on the userform

    Me.Hide
    'do some stuff
    Me.Show

  7. #7
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Minimizing a Userform

    Great, thanks, RoyUK!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1