Position Form on screen v Window Zoom !
sorry for my mistake.
Sub SetPos(r As Range)
Sub SetFormPos(r As Range)
is correct.
--
Regards,
okaizawa
okaizawa wrote:
Hi,
I am not sure if this could work always...
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Sub SetPos(r As Range)
Dim ws As Worksheet
Dim hdc As Long
Dim px As Long, py As Long
Dim x As Double, y As Double
Dim i As Long, z As Long
Set ws = r.Worksheet
hdc = GetDC(0)
px = GetDeviceCaps(hdc, LOGPIXELSX)
py = GetDeviceCaps(hdc, LOGPIXELSY)
ReleaseDC 0, hdc
z = ActiveWindow.Zoom
x = ActiveWindow.PointsToScreenPixelsX(0)
For i = 1 To r.Column - 1
x = x + Int(ws.Columns(i).Width * px * z / 7200 + 0.5000001)
Next
y = ActiveWindow.PointsToScreenPixelsY(0)
For i = 1 To r.Row - 1
y = y + Int(ws.Rows(i).Height * py * z / 7200 + 0.5000001)
Next
Me.Left = x * 72 / px
Me.Top = y * 72 / py
End Sub
Private Sub UserForm_Activate()
SetFormPos ActiveWindow.VisibleRange(2, 2)
End Sub
|