1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| Option Explicit
'----------------------------------------------------------------------------------------
Public Function GetRibbonTabFocus() As String
'----------------------------------------------------------------------------------------
' Sources:
' https://www.developpez.net/forums/d697439/logiciels/microsoft-office/general-vba/contribuez/introduction-aux-fonctions-d-accessibilite/
'----------------------------------------------------------------------------------------
Dim oChild As Variant
Dim oRibbon As IAccessible
Dim oTab As IAccessible
Dim MenuTabAddInsName As String
Const ROLE_SYSTEM_CLIENT = &HA&
Const ROLE_SYSTEM_WINDOW = &H9&
Const ROLE_SYSTEM_PAGETAB = &H25&
Const ROLE_SYSTEM_PROPERTYPAGE = &H26&
Const ROLE_SYSTEM_PAGETABLIST = &H3C&
On Error GoTo Gest_Err
'' Ribbon Tool Bar
Set oRibbon = CommandBars("ribbon")
' Ribbon Window
Set oRibbon = oRibbon.accChild(ByVal 1&)
' Ribbon Client
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_CLIENT)
' Ribbon Client Window
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_WINDOW)
'' Ribbon Client Window Client
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_CLIENT)
' Ribbon Client Window Client Window
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_WINDOW)
' Ribbon Property page
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_PROPERTYPAGE)
' Ribbon Tabs list
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_PAGETABLIST)
' Ribbon Tabs list Client
Set oRibbon = FindChildByRoleOrName(oRibbon, , ROLE_SYSTEM_CLIENT)
' Tab:
Set oTab = FindChildByRoleOrName(oRibbon, MenuTabAddInsName, ROLE_SYSTEM_PAGETAB)
' True if OK
GetRibbonTabFocus = MenuTabAddInsName
Exit Function
Gest_Err:
GetRibbonTabFocus = ""
Err.Clear
End Function
'----------------------------------------------------------------------------------------
Private Function FindChildByRoleOrName(pParent As IAccessible, _
Optional pChildName As String = "*", _
Optional pChildRole As String = "*") As IAccessible
'----------------------------------------------------------------------------------------
' Fonction privée pour rechercher un objet accessible à partir de son parent, son role et son nom
'----------------------------------------------------------------------------------------
Dim lName As String, lRole As Long
Dim oChild As IAccessible
Const NAVDIR_FIRSTCHILD = &H7&
Const NAVDIR_NEXT = &H5&
On Error GoTo Gest_Err
Set oChild = pParent.accNavigate(NAVDIR_FIRSTCHILD, ByVal 0&)
If pChildName <> "*" Then lName = oChild.accName(ByVal 0&)
If pChildRole <> "*" Then lRole = oChild.accRole(ByVal 0&)
If lRole Like pChildRole And lName Like pChildName Then
Set FindChildByRoleOrName = oChild
Exit Function
End If
Do
Set oChild = oChild.accNavigate(NAVDIR_NEXT, ByVal 0&)
If pChildName <> "*" Then lName = oChild.accName(ByVal 0&)
If pChildRole <> "*" Then lRole = oChild.accRole(ByVal 0&)
' Pour indiquer l'onglet actif:
If oChild.accState(ByVal 0&) = 3145730 Then
'Debug.Print "Onglet actif : " & oChild.accName(ByVal 0&)
pChildName = oChild.accName(ByVal 0&)
Exit Do
End If
If lRole Like pChildRole And lName Like pChildName Then
Set FindChildByRoleOrName = oChild
Exit Do
End If
Loop
Exit Function
Gest_Err:
Set FindChildByRoleOrName = Nothing
Err.Clear
End Function |
Partager