'--------------------------------------------
'Position UserForm sur un objet de la feuille
'--------------------------------------------
Sub PositionUserFormOnSheetObject(Usf As Object, _
SheetObject As Object, _
Optional HorizontalShift As Double = 0, _
Optional VerticalShift As Double = 0, _
Optional UserFormShiftLeft As Boolean = False, _
Optional UserFormShiftTop As Boolean = False)
Dim Coeff_PointToPixel As Double
Dim Coeff_PixelToPoint As Double
Dim Left As Long
Dim Top As Long
Dim ecx#
Dim op&
'Récupère les coefficients de conversion Points <-> Pixels
With ActiveWindow
Coeff_PointToPixel = (.ActivePane.PointsToScreenPixelsX(72) - .ActivePane.PointsToScreenPixelsX(0)) / 72 'coeff point to pixel
Coeff_PixelToPoint = 1 / Coeff_PointToPixel
'Calcule la position du UserForm
Left = (.ActivePane.PointsToScreenPixelsX(0) * Coeff_PixelToPoint + SheetObject.Left + HorizontalShift) * (.Zoom / 100)
If UserFormShiftLeft Then Left = Left - Usf.Width
Top = (.ActivePane.PointsToScreenPixelsY(0) * Coeff_PixelToPoint + SheetObject.Top + VerticalShift) * (.Zoom / 100)
If UserFormShiftTop Then Top = Top - Usf.Height
End With
op = Int(Val(Mid(Application.OperatingSystem, InStrRev(Application.OperatingSystem, " ") + 1))) 'number version system
ecx = 4 And op = 6 And Int(Val(Application.Version)) < 16 'ecart cadre grosse bordures 2007 et Windows 7
'Positionne le UserForm
With Usf
.StartUpPosition = 0
.Left = Left + ecx
.Top = Top + ecx
End With
End Sub