PDA

View Full Version : Resize userform VBA



agfac
12-20-2013, 07:34 AM
Hi,

I made an userform on a PC with 1920x1080 resolution but I want to test it on other PC with a lower resolution.

What is the best solution?

Thanks

mikerickson
12-20-2013, 07:56 AM
Solution to what?

A userform can be resized with code like

UserForm1.Top = 200
UserForm1.Left = 100
UserForm1.Show

agfac
12-20-2013, 08:07 AM
Solution to what?

A userform can be resized with code like

UserForm1.Top = 200
UserForm1.Left = 100
UserForm1.Show

It doesn't work.

But this do not resize the userform. It only locate it on the monitor. Am I right?

Kenneth Hobs
12-20-2013, 08:13 AM
Use the Width and Height properties.


Private Sub UserForm_Initialize()
With Me
.Top = 100
.Left = 100
.Height = 25
.Width = 300
End With
End Sub

agfac
12-20-2013, 08:22 AM
Use the Width and Height properties.


Private Sub UserForm_Initialize()
With Me
.Top = 100
.Left = 100
.Height = 25
.Width = 300
End With
End Sub


But it only resize the window. I want to resize window and all of your contents (textboxes, comboboxes, etc).

Is it possible to put resize arrows on the corners to resize the userform?

Kyle234
12-20-2013, 08:31 AM
Cross posted here: h t t p://w w w.mrexcel.com/forum/excel-questions/746291-resize-userform-visual-basic-applications.html

Kenneth Hobs
12-20-2013, 08:38 AM
A search is generally best prior to a post to a forum.

See: http://www.mrexcel.com/forum/excel-questions/558649-userform-movable-resizable.html

As Leith Ross said, resizing the controls as well is another matter.
Maybe you could use vb.net instead.

Another option might be to resize each control by a percentage as Ron de Bruin demonstrated in:
http://www.rondebruin.nl/mac/mac022.htm

e.g.

Private Sub UserForm_Initialize()
Dim f As Double, c As Control
f = 1.5
With Me
.Top = .Top * f
.Left = .Left * f
.Width = .Width * f
.Height = .Height * f
On Error Resume Next
.Font.Size = .Font.Size * f
On Error GoTo 0
For Each c In .Controls
With c
.Top = .Top * f
.Left = .Left * f
.Width = .Width * f
.Height = .Height * f
On Error Resume Next
.Font.Size = .Font.Size * f
On Error GoTo 0
End With
Next c
End With
End Sub

Jan Karel Pieterse
12-20-2013, 08:39 AM
One way is to switch your own monitor to a lower resolution.

Warning: it will wreck your current Icon layout.

mikerickson
12-20-2013, 08:46 AM
Regarding the size of the controls, as a user, I would rather have to scroll to a control than have to deal with small controls (and small fonts).

One could write code that would detect the resolution of the screen, resize the controls and adjust the font sizes to match.
But, as I said, if the controls (fonts) are too small, I'd prefer if the UF had scroll bars rather than tiny controls.
If the size/font of the small format is sufficiently large, then the larger version could be exactly the same userform.