'patricktoulon
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal dwData As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Private Sub CommandButton1_Click()
Dim cell As Range, x, y, pt As POINTAPI
Set cell = ActiveCell
GetCursorPos pt
'on prend les points de la cellule en dessous
With ActiveWindow.ActivePane
x = .PointsToScreenPixelsX(cell.Left)
y = .PointsToScreenPixelsY(cell.Offset(2).Top - 2)
End With
'on y place le curseur
SetCursorPos x, y
' on simule un clic gauche
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
DoEvents
SetCursorPos pt.x, pt.y
'si la cellule a changé au click souris simulé c'est que le userform est non modal sinon elle ne change pas donc modal
MsgBox "Modal : " & CStr(cell.Address = ActiveCell.Address)
cell.Select
End Sub