Public cel As Range
Public Function WindowXYFromPoint(x, y): WindowXYFromPoint = ExecuteExcel4Macro("CALL(""user32"",""WindowFromPoint"",""JJJ""," & x & ", " & y & ")"): End Function
Function placeOnRange(RNG As Range)
Dim PtPx#, EcX&, Ecy&, BL#, BH#, q1$, q2$, Lh&, th&
With ActiveWindow.ActivePane
PtPx = (.PointsToScreenPixelsX(72) - .PointsToScreenPixelsX(0)) / 72 'coeff pixel
If Not RNG Is Nothing Then x = .PointsToScreenPixelsX(RNG.Left): y = .PointsToScreenPixelsY(RNG.Top)
Lh = .PointsToScreenPixelsX([A1].Left + 10)
th = .PointsToScreenPixelsY([A1].Top + 10)
End With
h1.Value = WindowXYFromPoint(Lh, th) 'le handle sous un point precis dans la cellule A1
With Me
.StartUpPosition = 0
.Left = (x / PtPx * ActiveWindow.Zoom / 100) ' + 50 ' je deregle la position exemple je le met à +50 de left
.Top = (y / PtPx * ActiveWindow.Zoom / 100) ' - 50 ' je deregle la position exemple je le met à -50 de top
End With
h2.Value = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'handle fenetre active
End Function
Private Sub UserForm_Activate()
Set cel = [D5]
placeOnRange cel
End Sub