Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hdc As LongPtr, ByVal x As Long, ByVal y As Long) As Long
Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
'Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Sub test()
Dim obj
Set obj = ActiveSheet.OLEObjects("ListBox1")
MsgBox "ListBox1 " & CStr(HasScrollbarV(obj))
Set obj = ActiveSheet.OLEObjects("ListBox2")
MsgBox "ListBox2 " & CStr(HasScrollbarV(obj))
End Sub
Function HasScrollbarV(obj) As Boolean
Dim L1#, L2#, T#
With ActiveWindow.ActivePane
L1 = .PointsToScreenPixelsX(obj.Left) + 3
L2 = .PointsToScreenPixelsX(obj.Left + obj.Width) - 6 ' - .PointsToScreenPixelsX(0)
T = .PointsToScreenPixelsY(obj.Top) + 50
c1 = GetPixel(GetDC(0), L1, T)
c2 = GetPixel(GetDC(0), L2, T)
If c1 <> c2 Then HasScrollbarV = True
'SetCursorPos L2, T'juste pour tester ou est vraiment le cursor
End With
End Function