ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sizing a UserForm (https://www.excelbanter.com/excel-programming/306705-re-sizing-userform.html)

Doug Glancy

Sizing a UserForm
 
Paul,

I used this on a form that actually takes up the whole screen. You'd have
to tinker with the ratios to have it almost fill the screen. It works
fairly well, although the fonts might not look quite right:

Sub size_form_and_controls()

Dim start_height As Long, start_width As Long, new_height As Long, new_width
As Long
Dim height_ratio As Double, width_ratio As Double
Dim ctl As Control

With UserForm
start_height = 768 'default settings on your computer
start_width = 1024
new_height = Application.Height 'find current screen resolution
new_width = Application.Width
height_ratio = new_height / start_height 'ratio to apply to form and all
controls
width_ratio = new_width / start_width
.Height = new_height 'resize the whole form
.Width = new_width
For Each ctl In .Controls 'resize the controls and text
ctl.Top = ctl.Top * height_ratio
ctl.Left = ctl.Left * width_ratio
ctl.Height = ctl.Height * height_ratio
ctl.Width = ctl.Width * width_ratio
On Error Resume Next 'if control has no font then skip
ctl.Font.Size = ctl.Font.Size * height_ratio
On Error GoTo 0
Next ctl
End With

End Sub

hth,

Doug Glancy

"darryl26" wrote in message
...
Is there a way to have a userform sized to fit the user's screen?

My display is set at 1024x768 and the form takes up most of the screen,

but
I have some users whose display is 800x600 (for vision purposes) and they

can
only see half the form when they run the program.

I tried altering the Zoom property on the Userform but it cut off the text
on some of the controls on the userform and I'm hoping that there's a way

to
adjust everything at once.

Thanks!
Paul





HFB

Sizing a UserForm
 
Would doing this mean that if the form were printed, it would fill the
printed page also? I'm trying to make my form fill an A4 (portrait) page.
I've used the sizing controls to make the form as big as it will let me, but
there's still about two inches of blank space on the page when I print.

"Doug Glancy" wrote:

Paul,

I used this on a form that actually takes up the whole screen. You'd have
to tinker with the ratios to have it almost fill the screen. It works
fairly well, although the fonts might not look quite right:

Sub size_form_and_controls()

Dim start_height As Long, start_width As Long, new_height As Long, new_width
As Long
Dim height_ratio As Double, width_ratio As Double
Dim ctl As Control

With UserForm
start_height = 768 'default settings on your computer
start_width = 1024
new_height = Application.Height 'find current screen resolution
new_width = Application.Width
height_ratio = new_height / start_height 'ratio to apply to form and all
controls
width_ratio = new_width / start_width
.Height = new_height 'resize the whole form
.Width = new_width
For Each ctl In .Controls 'resize the controls and text
ctl.Top = ctl.Top * height_ratio
ctl.Left = ctl.Left * width_ratio
ctl.Height = ctl.Height * height_ratio
ctl.Width = ctl.Width * width_ratio
On Error Resume Next 'if control has no font then skip
ctl.Font.Size = ctl.Font.Size * height_ratio
On Error GoTo 0
Next ctl
End With

End Sub

hth,

Doug Glancy

"darryl26" wrote in message
...
Is there a way to have a userform sized to fit the user's screen?

My display is set at 1024x768 and the form takes up most of the screen,

but
I have some users whose display is 800x600 (for vision purposes) and they

can
only see half the form when they run the program.

I tried altering the Zoom property on the Userform but it cut off the text
on some of the controls on the userform and I'm hoping that there's a way

to
adjust everything at once.

Thanks!
Paul







All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com