Add Minimize Button to Userform

by Selva V Pasupathy

The following lines of codes will help add a minimize button on a userform which will be handy in many situations.

First copy the following 3 lines of codes to userform code window.

Private Sub UserForm_Initialize()
    Call FormatUserForm(Me.Caption)
End Sub

Copy the following code in a module.

Option Explicit
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
Sub ShowForm()
    UserForm1.Show
End Sub


For some more resources visit

-Selva V Pasupathy
HSBC Global Resourcing
Hyderabad, India

Advertisements

1 Comment »

  1. […] Add Minimize Button to Userform […]

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: