Function IsScrollable(control, Onsheet As Boolean) As Boolean
Dim PosControl As IAccessible, pos As POINTAPI, ok As Boolean, role, obj As Object
If control Is Nothing Then Exit Function
Select Case True
Case TypeOf control Is ComboBox: role = 33
Case TypeName(control) = "ListBox": role = 33
Case TypeOf control Is TextBox: role = 42
Case TypeOf control Is Frame: role = 20
Case TypeOf control Is UserForm: role = 16
'etc..
End Select
GetCursorPos pos
If Onsheet Then 'si on est dans une feuille et que le control n'est pas géré
DoEvents
Set obj = ActiveWindow.RangeFromPoint(pos.X, pos.Y): DoEvents
If TypeName(obj) <> "Range" Then DoEvents: If obj.Left <> control.Left Or obj.Top <> control.Top Then IsScrollable = False: Exit Function
Else
Dim c As New CUIAutomation
Dim UIAelem As IUIAutomationElement
Dim accescontrol As IAccessible
Set accescontrol = control
Set UIAelem = c.ElementFromIAccessible(accescontrol, 0)
If UIAelem.CurrentBoundingRectangle.Top < pos.Y And _
UIAelem.CurrentBoundingRectangle.Left < pos.X And _
UIAelem.CurrentBoundingRectangle.bottom > pos.Y And _
UIAelem.CurrentBoundingRectangle.Right > pos.X Then _
IsScrollable = False: Exit Function
End If
#If Win64 Then
Dim lngPtr As LongPtr
CopyMemory lngPtr, pos, LenB(pos)
AccessibleObjectFromPoint lngPtr, PosControl, 0
#Else
AccessibleObjectFromPoint pos.X, pos.Y, PosControl, 0
#End If
UserForm1.TextBox2 = "IAccessible :" & PosControl.accRole
'ratrapage pour la combobox quand elle n'est pas developpée
'on decale pos.y de 25 pour passer eventuellement SUR LA child si elle est developpée directement et donc scrollable a partir du bouton drop ou input
If PosControl.accRole <> role Then
If TypeOf control Is ComboBox Then
pos.Y = pos.Y + 25
#If Win64 Then
CopyMemory lngPtr, pos, LenB(pos)
AccessibleObjectFromPoint lngPtr, PosControl, 0
#Else
AccessibleObjectFromPoint pos.X, pos.Y, PosControl, 0
#End If
End If
End If
On Error Resume Next
'[c1] = PosControl.accRole
IsScrollable = PosControl.accRole = role
End Function