B
Brian
My problem is that the User Form is to big to fit on the Screen. It works
good on 1 Computer, but when I use A computer with a smaller Screen it
becomes way to big. When that happens 30% of the Form is cut off.
Is there a code that I can run on UserForm_Initialize that will size it for
the Screen. It would be nice if it would size according to the Display
settings.
I found this code here in the forumn but I can't get it to work.
Sub size_form_and_controls()
Dim start_height As Long
Dim start_width As Long
Dim new_height As Long
Dim new_width As Long
Dim height_ratio As Double
Dim width_ratio As Double
Dim ctl As Control
With Me
'default settings on your computer
start_height = 1024
start_width = 1280
'find current screen resolution
new_height = Application.Height
new_width = Application.Width
'ratio to apply to form and all Controls
height_ratio = new_height / start_height
width_ratio = new_width / start_width
'resize the whole form
.Height = new_height
.Width = new_width
'resize the controls and text
For Each ctl In .Controls
ctl.Top = ctl.Top * height_ratio
ctl.Left = ctl.Left * width_ratio
ctl.Height = ctl.Height * height_ratio
ctl.Width = ctl.Width * width_ratio
'if control has no font then skip
On Error Resume Next
ctl.Font.Size = ctl.Font.Size * height_ratio
On Error GoTo 0
Next ctl
End With
good on 1 Computer, but when I use A computer with a smaller Screen it
becomes way to big. When that happens 30% of the Form is cut off.
Is there a code that I can run on UserForm_Initialize that will size it for
the Screen. It would be nice if it would size according to the Display
settings.
I found this code here in the forumn but I can't get it to work.
Sub size_form_and_controls()
Dim start_height As Long
Dim start_width As Long
Dim new_height As Long
Dim new_width As Long
Dim height_ratio As Double
Dim width_ratio As Double
Dim ctl As Control
With Me
'default settings on your computer
start_height = 1024
start_width = 1280
'find current screen resolution
new_height = Application.Height
new_width = Application.Width
'ratio to apply to form and all Controls
height_ratio = new_height / start_height
width_ratio = new_width / start_width
'resize the whole form
.Height = new_height
.Width = new_width
'resize the controls and text
For Each ctl In .Controls
ctl.Top = ctl.Top * height_ratio
ctl.Left = ctl.Left * width_ratio
ctl.Height = ctl.Height * height_ratio
ctl.Width = ctl.Width * width_ratio
'if control has no font then skip
On Error Resume Next
ctl.Font.Size = ctl.Font.Size * height_ratio
On Error GoTo 0
Next ctl
End With