View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default UserForm positioning to second row


Hi D..
Try following

You'll need the APIs as VBA thinks all monitors are 72dpi.
Now it even works on my dual monitor (vertical) setup.


'Insert this code to your form:
Option Explicit

Private Declare Function GetDC Lib "user32.dll" ( _
ByVal hwnd&) As Long
Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd&, ByVal hDC&) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC&, ByVal nIndex&) As Long
Function ScreenRes&(iDir%)
Dim lDC&
Static res
If Not IsArray(res) Then
ReDim res(1) As Long
lDC = GetDC(0)
res(0) = GetDeviceCaps(lDC, 88&)
res(1) = GetDeviceCaps(lDC, 90&)
lDC = ReleaseDC(0, lDC)
End If
ScreenRes = res(iDir)
End Function


Private Sub UserForm_Activate()
With ActiveWindow
Me.Top = .PointsToScreenPixelsY(.VisibleRange.Rows( _
2).Top) * 72 / ScreenRes(0)
Me.Left = .PointsToScreenPixelsX(.VisibleRange.Columns( _
1).Left) * 72 / ScreenRes(1)
End With

End Sub








--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


z wrote :

I am using Excel in Office 2000. I need to show a userform that is
positioned with it's top aligned with the top of the second visible
row of the active worksheet. It also needs to have it's left side
aligned with the left side of the second visible column.

It seems userforms use screen offsets, and Excel rows and columns use
the Inner offset of the worksheet. How do I translate the row and
column coordinates to screen offsets? If the user has Excel not
maximized, for example, or if there are custom menu bars which scoot
the top of the activesheet down, then it becomes difficult to know
what the UserForm coordinates need to be.

D Zook