Start a userform maximised

Jean-Francois

New Member
Joined
Jul 23, 2009
Messages
27
Hi there,

I know how to add a min/max button to a userform but is it possible to make a userform initialise maximised ?

Cant seem to make it work for some reason.

Using Office 2007

Thank you
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi there,

Try:

Code:
Private Sub UserForm_Initialize()
    Application.WindowState = xlMaximized
    Me.Width = Application.Width
    Me.Height = Application.Height
End Sub
 
Upvote 0
Greetings Jean-Francois,

Contrived from: http://www.eggheadcafe.com/software/aspnet/31512126/maximizing-the-size-of-a-userform.aspx

...excepting that I have the function return a Boolean, as I'd rather things stop there if we fail to return a proper handle.

Anyways, in a Standard Module:
Rich (BB code):
Option Explicit
    
Public Declare Function GetDesktopWindow Lib "user32" () As Long
    
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    
Public Declare Function FindWindowEx Lib "user32" _
                        Alias "FindWindowExA" (ByVal hWnd1 As Long, _
                                               ByVal hWnd2 As Long, _
                                               ByVal lpsz1 As String, _
                                               ByVal lpsz2 As String _
                                               ) As Long
    
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
                                                               ByRef lpdwProcessId As Long _
                                                               ) As Long
    
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
                                                 ByVal nCmdShow As Long _
                                                 ) As Long
    
Public Const SW_MAXIMIZE = &H3
    
Function FindThisWindow(ByRef hwnd As Long, _
                        Optional ByVal WindowCaption As String, _
                        Optional ByVal WinClass As String _
                        ) As Boolean
Dim _
hwndDeskTop     As Long, _
lCurrProc       As Long, _
lWinProc        As Long
    
    lCurrProc = GetCurrentProcessId()
    hwndDeskTop = GetDesktopWindow()
    
    Do
        hwnd = FindWindowEx(hwndDeskTop, hwnd, WinClass, WindowCaption)
        Call GetWindowThreadProcessId(hwnd, lWinProc)
    Loop Until lWinProc = lCurrProc Or hwnd = 0
    
    FindThisWindow = Not hwnd = 0
End Function

In the Userform's Module:
Rich (BB code):
Private Sub UserForm_Activate()
Dim hwnd As Long
    
    If FindThisWindow(hwnd, Me.Caption) Then
        ShowWindow hwnd, SW_MAXIMIZE
    End If
End Sub
Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top