ben tu ajoute respectivement range(premiere cellulemobile,obj).height et width a leur contexte et tu devrait avoir ton userform en bottom et right
Sub test2(obj As Object)
Dim Z#, EcX#, EcY#, L1#, T1#, nextcolfreeze#, nextrowfreeze#, H#, L#
With ActiveWindow
Z = (ActiveWindow.Zoom / 100)
EcX = 4 / Z
EcY = 3 / Z
L1 = (.ActivePane.PointsToScreenPixelsX(obj.Left) / PtoPx) * Z
T1 = .ActivePane.PointsToScreenPixelsY(obj.Top) / PtoPx * Z
nextcolfreeze = 5 ' je suis obligé de les coder en dur splitrow donne 3 pour les 3 colonnes visible (je veux 5)
nextrowfreeze = 6 ' il faudrait que ce soit pareil ici au cas ou des rows dans le splitrow seraient scrollées
If obj.Column <= nextcolfreeze Then L1 = (obj.Left + (.ActivePane.PointsToScreenPixelsX(0) / PtoPx)) * Z
If obj.Row < nextrowfreeze Then T1 = (obj.Top + (.ActivePane.PointsToScreenPixelsY(0) / PtoPx)) * Z
If .ScrollRow > 1 + nextrowfreeze And obj.Row <= nextrowfreeze Then 'ca fonctionne
H = Range(Cells(nextrowfreeze + 2, 1), .VisibleRange.Cells(1)).Height * Z
T1 = T1 + H
End If
If .ScrollColumn > 1 + nextcolfreeze And obj.Column <= nextcolfreeze Then' ca fonctionne pas
L = Range(Cells(nextcolfreeze + 2, 1), .VisibleRange.Cells(1)).Width * Z
L1 = L1 + L
'MsgBox h
End If
End With
With UserForm1
.Show 0
.Left = L1 + EcX
.Top = T1 + (EcY * Z)
End With
End Sub
Tu m'inquiètes là, avec ça. Aurais-je fini par virer à tort quelque chose qu'il fallait garder, à force de toujours voir partout que 3 points correspondaient toujours à 4 pixels ?à propos du dpi chez moi c'est pas 1.3333 mais 1.60
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function GetDC& Lib "user32.dll" (ByVal hWnd&)
Private Declare PtrSafe Function GetDeviceCaps& Lib "gdi32" (ByVal hDC&, ByVal nIndex&)
#Else
Private Declare Function GetDC& Lib "user32.dll" (ByVal hWnd&)
Private Declare Function GetDeviceCaps& Lib "gdi32" (ByVal hDC&, ByVal nIndex&)
#End If
Sub Test()
MsgBox GetDeviceCaps(GetDC(0), 88) / 72 & " pixels par point horizontalement," & vbLf _
& GetDeviceCaps(GetDC(0), 90) / 72 & " pixels par point verticalement.", vbInformation
End Sub
Sub test()
Dim i As Double
For i = 50 To 250 Step 10
ActiveWindow.Zoom = i
Debug.Print "zoom" & i & " " & Cells(4, 3).Width * (ActiveWindow.Zoom / 100)
Next
End Sub
zoom50 31,2
zoom60 37,44
zoom70 43,68
zoom80 49,92
zoom90 56,16
zoom100 62,4
zoom110 68,64
zoom120 74,88
zoom130 81,12
zoom140 87,36
zoom150 93,6
zoom160 99,84
zoom170 106,08
zoom180 112,32
zoom190 118,56
zoom200 124,8
zoom210 131,04
zoom220 137,28
zoom230 143,52
zoom240 149,76
zoom250 156
Sub test2(obj As Object)
Dim Z#, EcX#, EcY#, L1#, T1#, nextcolfreeze#, nextrowfreeze#, H#, L#
With ActiveWindow
Z = (ActiveWindow.Zoom / 100)
EcX = 2
EcY = 3
L1 = (.ActivePane.PointsToScreenPixelsX(obj.Left) / PtoPx) * Z + EcX
T1 = .ActivePane.PointsToScreenPixelsY(obj.Top) / PtoPx * Z
nextcolfreeze = Cells(, .SplitColumn).Column
nextrowfreeze = Cells(.SplitRow, 1).Row
Left0 = (.ActivePane.PointsToScreenPixelsX(0) / PtoPx)
If obj.Column <= nextcolfreeze Then L1 = (obj.Left + (.ActivePane.PointsToScreenPixelsX(0) / PtoPx)) * Z
If obj.Row < nextrowfreeze Then T1 = (obj.Top + (.ActivePane.PointsToScreenPixelsY(0) / PtoPx)) * Z
If .ScrollRow > 1 + nextrowfreeze And obj.Row <= nextrowfreeze Then
H = Range(Cells(nextrowfreeze + 2, 1), .VisibleRange.Cells(1)).Height * Z
T1 = T1 + H
End If
If .ScrollColumn >= nextcolfreeze And obj.Column <= nextcolfreeze Then
L1 = (obj.Left * Z) + Left0 + (EcX * Z)
End If
End With
With UserForm1
.Show 0
.Left = L1 + EcX
.Top = T1 + (EcY * Z)
End With
End Sub
Private Function PtoPx()
With ActiveWindow.ActivePane:
PtoPx = (.PointsToScreenPixelsX(Cells.Width) - .PointsToScreenPixelsX(0)) / Cells.Width
End With
End Function
#If VBA7 Then
Private Declare PtrSafe Function GetDC& Lib "user32.dll" (ByVal hWnd&)
Private Declare PtrSafe Function GetDeviceCaps& Lib "gdi32" (ByVal hDC&, ByVal nIndex&)
#Else
Private Declare Function GetDC& Lib "user32.dll" (ByVal hWnd&)
Private Declare Function GetDeviceCaps& Lib "gdi32" (ByVal hDC&, ByVal nIndex&)
#End If
Dim … , Zom As Double, Px72 As Long, Trnq As Long
Zom = ActiveWindow.Zoom / 100
Px72 = GetDeviceCaps(GetDC(0), 88)
If ActiveWindow.FreezePanes Then
Lft = Obj.Left: Trnq = Int(Lft / 3) * 3
Lft = ActiveWindow.ActivePane.PointsToScreenPixelsX(Trnq) * 72 / Px72 + (Lft - Trnq)
Else
Lft = ActiveWindow.PointsToScreenPixelsX(Int(Obj.Left * Zom * Px72 / 72 + 0.5)) * 72 / Px72
End If
Px72 = GetDeviceCaps(GetDC(0), 90)
If ActiveWindow.FreezePanes Then
Top = Obj.Top: Trnq = Int(Top / 3) * 3
Top = ActiveWindow.ActivePane.PointsToScreenPixelsY(Trnq) * 72 / Px72 + (Top - Trnq)
Else
Top = ActiveWindow.PointsToScreenPixelsY(Int(Obj.Top * Zom * Px72 / 72 + 0.5)) * 72 / Px72
End If
Rgt = Lft + Obj.Width * Zom: Bot = Top + Obj.Height * Zom