Public cel As Range
Public Function WindowXYFromPoint(x, y): WindowXYFromPoint = ExecuteExcel4Macro("CALL(""user32"",""WindowFromPoint"",""JJJ""," & x & ", " & y & ")"): End Function
Public Function ShowOnCell(cel As Range, Optional modal As Boolean = vbModal)
With UserForm2: Set .cel = cel: .Show modal: End With
End Function
Function placeOnRange(RNG As Range)
Dim h2&, H1&, PtPx#, EcX&, Ecy&
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)
End With
EcX = Me.Width - 50 'ecart maximum toléré par la fonction en pixel
Ecy = Me.Height - 50 'ecart maximum toléré par la fonction en pixel
H1 = WindowXYFromPoint(x, y)
With Me
.StartUpPosition = 0
.Left = (x / PtPx * ActiveWindow.Zoom / 100) + 15 ' je deregle la position exemple je le met à -100 de left
.Top = (y / PtPx * ActiveWindow.Zoom / 100) + 15 ' je deregle la position exemple je le met à +10 de top
End With
'correction Left
h2 = WindowXYFromPoint(x, y + Ecy)
If h2 <> H1 Then
Do While h2 <> H1 And b < 150: Me.Left = Me.Left + 0.1: h2 = WindowXYFromPoint(x, y + Ecy): b = b + 1: Loop: Me.Left = Me.Left - 1
Else
b = 0
Do While h2 = H1 And b < 150: Me.Left = Me.Left - 0.1: h2 = WindowXYFromPoint(x, y + Ecy): b = b + 1: Loop: Me.Left = Me.Left - 1
End If
'correction top
h2 = WindowXYFromPoint(x + EcX, y)
If h2 <> H1 Then
b = 0
Do While h2 <> H1 And b < 150: Me.Top = Me.Top + 0.1: h2 = WindowXYFromPoint(x + EcX, y): b = b + 1: Loop: Me.Top = Me.Top - 1
Else
b = 0
Do While h2 = H1 And b < 150: Me.Top = Me.Top - 0.1: h2 = WindowXYFromPoint(x + EcX, y): b = b + 1: Loop: Me.Top = Me.Top - 1 'on le repousse donc en bas
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Sub UserForm_Activate()
If cel Is Nothing Then Set cel = [D5]
placeOnRange cel
End Sub
Public cel As Range
Public Function WindowXYFromPoint(x, y): WindowXYFromPoint = ExecuteExcel4Macro("CALL(""user32"",""WindowFromPoint"",""JJJ""," & x & ", " & y & ")"): End Function
Public Function ShowOnCell(cel As Range, Optional modal As Boolean = vbModal)
With UserForm2: Set .cel = cel: .Show modal: End With
End Function
Function placeOnRange(RNG As Range)
Dim h2&, H1&, PtPx#, EcX&, Ecy&, BL#, BH#, q1$, q2$
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)
End With
EcX = Me.Width - 50
Ecy = Me.Height - 50
H1 = WindowXYFromPoint(x - 50, y - 50)
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
'correction Left
h2 = WindowXYFromPoint(x, y + Ecy)
If h2 <> H1 Then
q1 = "-"
Do While h2 <> H1 And BL < 1000: Me.Left = Me.Left + 0.1: h2 = WindowXYFromPoint(x, y + Ecy): BL = BL + 1: Loop: Me.Left = Me.Left - 0.1
Else
q1 = "+"
BL = 0
Do While h2 = H1 And BL < 1000: Me.Left = Me.Left - 0.1: h2 = WindowXYFromPoint(x, y + Ecy): BL = BL + 1: Loop: Me.Left = Me.Left - 0.1
End If
'correction top
h2 = WindowXYFromPoint(x + EcX, y)
If h2 <> H1 Then
BH = 0
q2 = "-"
Do While h2 <> H1 And BH < 1000: Me.Top = Me.Top + 0.1: h2 = WindowXYFromPoint(x + EcX, y): BH = BH + 1: Loop: Me.Top = Me.Top - 0.1
Else
BH = 0
q2 = "+"
Do While h2 = H1 And BH < 1000: Me.Top = Me.Top - 0.1: h2 = WindowXYFromPoint(x + EcX, y): BH = BH + 1: Loop: Me.Top = Me.Top - 0.1 'on le repousse donc en bas
End If
MsgBox "il y avait " & q1 & BL / 10 & " de decalage left et " & q2 & BH / 10 & " de décalage top "
End Function
'////////////////////////////////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Sub UserForm_Activate()
If cel Is Nothing Then Set cel = [D5]
placeOnRange cel
End Sub
Private Sub UserForm_Activate()
With ActiveWindow.ActivePane
PtPx = (.PointsToScreenPixelsX(72) - .PointsToScreenPixelsX(0)) / 72 'coeff pixel
z = ActiveWindow.Zoom / 100
l = (.PointsToScreenPixelsX([c3].Left) / PtPx) * z
t = (.PointsToScreenPixelsY([c3].Top) / PtPx) * z
End With
Me.Move l, t
End Sub
Do While h2 <> H1 And BL < 1000: Me.Left = Me.Left + 0.1: h2 = WindowXYFromPoint(x, y + Ecy): BL = BL + 1: Loop: Me.Left = Me.Left - 0.1
LOL office365, c'est l'avenir = juste pour te motiverBonjour @Usine à gaz
bon ben 365 vous vous en passerez car là je vois pas
si les handles ne sont pas captés ou que pointstoscreenpixels ne fonctionne pas chez vous ,je ne peux plus rien faire
j'ai testé chez moi 2013 et 2016
avec le userform
plus haut et plus a droite
plus haut et plus a gauche
plus bas et plus a droite
plus bas et plus a gauche
le userform revient toujours a sa place
peut être que c'est un truc qui a été supprimé sur 365
ça serait logique la gestion de fenêtre n’étant pas la même il est normale que pointstoscreenpixels soit disabled aussi
ou alors il faut faire sauter les activepane du code
donne moi simplement une cature avec ça dans un userform
essaie avec ".activepane" et sansVB:Private Sub UserForm_Activate() With ActiveWindow.ActivePane PtPx = (.PointsToScreenPixelsX(72) - .PointsToScreenPixelsX(0)) / 72 'coeff pixel z = ActiveWindow.Zoom / 100 l = (.PointsToScreenPixelsX([c3].Left) / PtPx) * z t = (.PointsToScreenPixelsY([c3].Top) / PtPx) * z End With Me.Move l, t End Sub
si ca marche pas c'est que vous n'avez plus cette fonction dispo sur votre version
Public cel As Range
Public Function WindowXYFromPoint(x, y): WindowXYFromPoint = ExecuteExcel4Macro("CALL(""user32"",""WindowFromPoint"",""JJJ""," & x & ", " & y & ")"): End Function
Public Function ShowOnCell(cel As Range, Optional modal As Boolean = vbModal)
With UserForm2: Set .cel = cel: .Show modal: End With
End Function
Function placeOnRange(RNG As Range)
Dim h2&, H1&, PtPx#, EcX&, Ecy&, BL#, BH#, q1$, q2$, Lh&
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)
End With
EcX = Me.Width - 50
Ecy = Me.Height - 50
H1 = WindowXYFromPoint(Lh, y - 50)
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
'correction Left
h2 = WindowXYFromPoint(x, y + Ecy)
MsgBox H1 & vbCrLf & h2
Exit function
If h2 <> H1 Then
q1 = "-"
Do While h2 <> H1 And BL < 1000: Me.Left = Me.Left + 0.1: h2 = WindowXYFromPoint(x, y + Ecy): BL = BL + 1: Loop: Me.Left = Me.Left - 0.1
Else
q1 = "+"
BL = 0
Do While h2 = H1 And BL < 1000: Me.Left = Me.Left - 0.1: h2 = WindowXYFromPoint(x, y + Ecy): BL = BL + 1: Loop: Me.Left = Me.Left - 0.1
End If
'correction top
h2 = WindowXYFromPoint(x + EcX, y)
If h2 <> H1 Then
BH = 0
q2 = "-"
Do While h2 <> H1 And BH < 1000: Me.Top = Me.Top + 0.1: h2 = WindowXYFromPoint(x + EcX, y): BH = BH + 1: Loop: Me.Top = Me.Top - 0.1
Else
BH = 0
q2 = "+"
Do While h2 = H1 And BH < 1000: Me.Top = Me.Top - 0.1: h2 = WindowXYFromPoint(x + EcX, y): BH = BH + 1: Loop: Me.Top = Me.Top - 0.1 'on le repousse donc en bas
End If
MsgBox "il y avait " & q1 & BL / 10 & " de decalage left et " & q2 & BH / 10 & " de decalage top "
End Function
'////////////////////////////////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Sub UserForm_Activate()
If cel Is Nothing Then Set cel = [D5]
placeOnRange cel
End Sub