1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Function PositionForm(usf, rng)
Dim Z As Double, K As Double
Z = ActiveWindow.Zoom / 100
K = ((ActiveWindow.ActivePane.PointsToScreenPixelsX(ActiveSheet.[A1].Width) - ActiveWindow.ActivePane.PointsToScreenPixelsX(0)) / ActiveSheet.[A1].Width) / Z
lleft = (ActiveWindow.PointsToScreenPixelsX(rng.Left * K * Z) / K) - 5
ttop = ActiveWindow.PointsToScreenPixelsY(rng.Top * K * Z) / K
Wwidth = IIf(rng.Columns.Count > 1, (rng.Width * Z) + 10, usf.Width)
Hheight = IIf(rng.Rows.Count > 1, (rng.Height * Z) + 5, usf.Height)
PositionForm = Array(lleft, ttop, Wwidth, Hheight)
End Function
Sub TestUserform()
r = PositionForm(UserForm1, ActiveCell)
With UserForm1: .Show 0: .Left = r(0): .Top = r(1): End With
End Sub
Sub TestUserformDansPlage()
r = PositionForm(UserForm1, [B3:F12])
With UserForm1: .Show 0: .Left = r(0): .Top = r(1): .Width = r(2): .Height = r(3): End With
End Sub
Sub TestUserformtopleftcell()
r = PositionForm(UserForm1, [B3])
With UserForm1: .Show 0: .Left = r(0): .Top = r(1): End With
End Sub |
Partager