View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 292
Default How to control the UserForm's position?

There is no Screen object like in VB, and Excel's metrics is not pixels
either -at least not all over. But this places the userform down right on my
screen, no matter what and where the Excel window is:

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

Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Sub test()
Dim X As Long, Y As Long
X = GetSystemMetrics32(SM_CXSCREEN)
Y = GetSystemMetrics32(SM_CYSCREEN)
With UserForm1
..StartUpPosition = 0
..Top = (Y - .Height - 50) * 0.71
..Left = (X - .Width - 50) * 0.71
..Show
End With
End Sub

Code modified from http://www.j-walk.com/ss/excel/tips/tip06.htm

HTH. Best wishes Harald

"OKLover" skrev i melding
...
Hello, All

Is anyone knows how to control the UserForm's position?
It seems that i couldn't to find the Screen.Width or Screen.Height
property in VBA.