ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   size of user form (https://www.excelbanter.com/excel-programming/302664-size-user-form.html)

jon brennan

size of user form
 
Is there a way of getting a user form in excel to adjust in size to fi
an individuals screen. I have a form that shows up completly on a 17
screen but gets cutoff on a 15" scree

--
Message posted from http://www.ExcelForum.com


Mark Thorpe

size of user form
 
As far as I know, you'll need to use the Windows API function
GetSystemMetrics32 to get the screen resolution. Also, the units used by
UserForm.Move don't seem to be on the same scale as screen resolution - you
have to multiply resolution by 3/4.

GetSystemMetrics32 declaration and sample code for setting the size of your
form are below. Note that this form will cover up your taskbar. You can
reduce the height a bit to account for that, but that will assume that the
user's task bar is on the bottom of the screen. To truly account for the
taskbar, regardless of its position, there is a separate API function called
SystemParametersInfo that you'd need to use. This would be more complicated!


Declare Function GetSystemMetrics32 Lib "User32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Sub ShowMaximizedForm()
Dim screenw As Long, screenh As Long
screenw = GetSystemMetrics32(0) ' screenwidth in points
screenh = GetSystemMetrics32(1) ' screenheight in points

UserForm1.Move 0, 0, screenw * .75, screenh * .75
UserForm1.Show

End Sub




All times are GMT +1. The time now is 08:44 AM.

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