PDA

View Full Version : Solved: maximise user form



bodhi
11-03-2005, 04:41 PM
Hi all,

i want to have a user form that maximises on opening. The problem that i am having is that if i use a computer that has a different screen resolution, the size of the form no longer fills the screen or is too big.

Is there a way to maximise the user form depending on the users resolution settings? Any help would be greatly appreciated.

I am only new to programming with VBA so the simpler the code the better.

http://vbaexpress.com/forum/images/smilies/102.gif

Bob Phillips
11-03-2005, 05:17 PM
Hi all,

i want to have a user form that maximises on opening. The problem that i am having is that if i use a computer that has a different screen resolution, the size of the form no longer fills the screen or is too big.

Is there a way to maximise the user form depending on the users resolution settings? Any help would be greatly appreciated.

I am only new to programming with VBA so the simpler the code the better.

http://vbaexpress.com/forum/images/smilies/102.gif
bodhi,

This code will make the userform the same size as Excel is currently set at. Add it to the Userform_Activate event


Application.WindowState = xlMaximized
With Application
Me.Top = .Top
Me.Left = .Left
Me.Height = .Height
Me.Width = .Width
End With

bodhi
11-03-2005, 05:41 PM
xld,

thanks for your reply...the code works a treat but i was after a way of ensuring that the user form is maximised when it opens. In your solution, if excel is not maximised, the user form will not be maximised. Is there any way to maximise the user form without it depending on excel being maximised?

Thanks for your help.
http://vbaexpress.com/forum/images/smilies/beerchug.gif

Ken Puls
11-03-2005, 11:24 PM
I think that this should do it for you. Even with Excel in a half screen state, the userform takes up the entire screen:

Option Explicit

Public lScrWidth As Long, lScrHeight As Long
Private Declare Function GetSystemMetrics32 Lib "User32" _
Alias "GetSystemMetrics" (ByVal lIndex As Long) As Long

Private Sub MonitorInfo()
lScrWidth = GetSystemMetrics32(0) '< in pixels
lScrHeight = GetSystemMetrics32(1)
End Sub

Private Sub UserForm_Initialize()
'Figure out the screen size
Call MonitorInfo

With Me
'Set top left corner of userform to top left of screen
.Top = 1
.Left = 1

'Set userform width to screen width
'Uses points which are approx 3/4 pixel
.Width = lScrWidth * 0.75

'Set userform height to screen height
'Subtract 10 points for taskbar height
.Height = lScrHeight * 0.75 - 10
End With

End Sub

EDIT: This entire thing goes in a userform module. The first 4 lines of text MUST be at the top of the module as well.

bodhi
11-04-2005, 12:20 AM
Thanks Ken,

I will have a look at it and get back to you (it's just about knock off time here on friday afternoon)
http://vbaexpress.com/forum/images/smilies/beerchug.gifhttp://vbaexpress.com/forum/images/smilies/beerchug.gif
...it maybe a couple of days before you here from me.

Thanks again,
Brent.

bodhi
11-06-2005, 04:00 PM
Ken,

The code you provided works perfectly.

Thanks for your help, it is much appreciated.

Brent.
http://vbaexpress.com/forum/images/smilies/023.gif

Ken Puls
11-06-2005, 05:31 PM
Great!

Thanks for the update! :)