Programmatically maximize a userform

G

Gussie

I am creating a UserForm in excel but there is no way to automaticaly
maximize the form, I have created a function that resizes form to the area
used and added a maximize button but client wants it to be maximized when
opening form.

Can this be done?
 
Z

Zone

Private Sub Userform_Initialize()
me.width=application.width
me.height=application.height
End sub
 
G

Gussie

I tried that but it does not give me the entire area, it returns just the
active spreadsheet area. I downloaded the FormFun.xls but it just shows how
to add the maximize/minimize buttons. I usually work with Access and I use a
cmd.Maximize (or something like that)

Thanks!
 
R

RB Smissaert

Option Explicit
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow _
Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

Function GetFormHwnd(strCaption As String) As Long
If Val(Application.Version) >= 9 Then
GetFormHwnd = FindWindow("ThunderDFrame", strCaption)
Else
GetFormHwnd = FindWindow("ThunderXFrame", strCaption)
End If
End Function

Private Sub UserForm_Initialize()

ShowWindow GetFormHwnd(Me.Caption), 3

End Sub


RBS
 
S

Steve Yandl

This might do the trick, assuming none of the PCs are Win98 or earlier.

___________________________________

Private Sub UserForm_Initialize()
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next

Me.Width = intHorizontal
Me.Height = intVertical

End Sub

__________________________________

Steve
 
G

Gussie

Thank you very much!

RB Smissaert said:
Option Explicit
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow _
Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

Function GetFormHwnd(strCaption As String) As Long
If Val(Application.Version) >= 9 Then
GetFormHwnd = FindWindow("ThunderDFrame", strCaption)
Else
GetFormHwnd = FindWindow("ThunderXFrame", strCaption)
End If
End Function

Private Sub UserForm_Initialize()

ShowWindow GetFormHwnd(Me.Caption), 3

End Sub


RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top