'--------------------------------------------
'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&
Dim zoomer#
'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
zoomer = .Zoom / 100
'Calcule la position du UserForm
Left = (.ActivePane.PointsToScreenPixelsX(0) * Coeff_PixelToPoint + SheetObject.Left + HorizontalShift) * (zoomer)
If UserFormShiftLeft Then Left = Left - Usf.Width
Top = (.ActivePane.PointsToScreenPixelsY(0) * Coeff_PixelToPoint + SheetObject.Top + VerticalShift) * (zoomer)
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 * zoomer)
.Top = Top + (ecx * zoomer)
End With
End Sub