Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default User Form Display Question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User Form Display Question

I built this code for the same issue you're having. Just call this procedure
in your userforms Intialize Event. Hope this helps! If so, let me know,
click "YES" below.

Sub AdjustScreenSize()

' move user form to upper left of screen and show scoll bars
With ProductForm

' if form is wider and higher than window width
If .Height Application.Height And .Width Application.Width Then

' increae height/width of userform so scroll bar doesn't cover
controls
.Width = .Width + 15
.Height = .Height + 15

' add scroll bars
.ScrollBars = 3 ' 3 show both hor./ver. bar
.ScrollHeight = .Height
.ScrollWidth = .Width

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If

' if form is taller than window height
If .Height Application.Height Then

' increase height of userform so scroll bar doesn't cover controls
.Width = .Width + 15

' add horizontal scroll bars
.ScrollBars = 2 ' 2 show ver. bar
.ScrollHeight = .Height

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height

Exit Sub
End If

' if form is wider than window width
If .Width Application.Width Then

' increae height of userform so scroll bar doesn't cover controls
.Height = .Height + 15

' add horizontal scroll bars
.ScrollBars = 1 ' 1 show hor. bar
.ScrollWidth = .Width

' adjust position of userform
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If
End With

End Sub
--
Cheers,
Ryan


"Brian" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default User Form Display Question

It works.

I was really hoping to it would resize the user form according to the screen
size though. Can that be done? Is it possible to resize the user form
according to the screen size?


Thanks


"Ryan H" wrote:

I built this code for the same issue you're having. Just call this procedure
in your userforms Intialize Event. Hope this helps! If so, let me know,
click "YES" below.

Sub AdjustScreenSize()

' move user form to upper left of screen and show scoll bars
With ProductForm

' if form is wider and higher than window width
If .Height Application.Height And .Width Application.Width Then

' increae height/width of userform so scroll bar doesn't cover
controls
.Width = .Width + 15
.Height = .Height + 15

' add scroll bars
.ScrollBars = 3 ' 3 show both hor./ver. bar
.ScrollHeight = .Height
.ScrollWidth = .Width

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If

' if form is taller than window height
If .Height Application.Height Then

' increase height of userform so scroll bar doesn't cover controls
.Width = .Width + 15

' add horizontal scroll bars
.ScrollBars = 2 ' 2 show ver. bar
.ScrollHeight = .Height

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height

Exit Sub
End If

' if form is wider than window width
If .Width Application.Width Then

' increae height of userform so scroll bar doesn't cover controls
.Height = .Height + 15

' add horizontal scroll bars
.ScrollBars = 1 ' 1 show hor. bar
.ScrollWidth = .Width

' adjust position of userform
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If
End With

End Sub
--
Cheers,
Ryan


"Brian" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User Form Display Question

I believe this code should work for what ever screen size you have. Plus, it
will adjust the userform size in case your user has the Excel application not
maximized.
--
Cheers,
Ryan


"Brian" wrote:

It works.

I was really hoping to it would resize the user form according to the screen
size though. Can that be done? Is it possible to resize the user form
according to the screen size?


Thanks


"Ryan H" wrote:

I built this code for the same issue you're having. Just call this procedure
in your userforms Intialize Event. Hope this helps! If so, let me know,
click "YES" below.

Sub AdjustScreenSize()

' move user form to upper left of screen and show scoll bars
With ProductForm

' if form is wider and higher than window width
If .Height Application.Height And .Width Application.Width Then

' increae height/width of userform so scroll bar doesn't cover
controls
.Width = .Width + 15
.Height = .Height + 15

' add scroll bars
.ScrollBars = 3 ' 3 show both hor./ver. bar
.ScrollHeight = .Height
.ScrollWidth = .Width

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If

' if form is taller than window height
If .Height Application.Height Then

' increase height of userform so scroll bar doesn't cover controls
.Width = .Width + 15

' add horizontal scroll bars
.ScrollBars = 2 ' 2 show ver. bar
.ScrollHeight = .Height

' adjust position of userform
.Top = Application.Top
.Height = ActiveWindow.Height

Exit Sub
End If

' if form is wider than window width
If .Width Application.Width Then

' increae height of userform so scroll bar doesn't cover controls
.Height = .Height + 15

' add horizontal scroll bars
.ScrollBars = 1 ' 1 show hor. bar
.ScrollWidth = .Width

' adjust position of userform
.Left = Application.Left
.Width = ActiveWindow.Width

Exit Sub
End If
End With

End Sub
--
Cheers,
Ryan


"Brian" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
display a user form WBTKbeezy Excel Programming 0 June 2nd 06 08:41 PM
user form question: text box to display result BigPig Excel Discussion (Misc queries) 0 February 28th 06 12:33 AM
user form question: text box to display result BigPig Excel Worksheet Functions 0 February 25th 06 08:17 PM
How to display =x/y result in a user form AndyRoo Excel Programming 2 November 25th 05 02:41 PM
User Form to display more than 1 reslut EstherJ Excel Programming 1 August 23rd 04 01:40 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"