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
|
Public Function SetRibbonTabFocus(pTab As String) As Boolean
Dim oChild As Variant
Dim oRibbon As IAccessible
Dim oTab As IAccessible
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 gestion_erreurs
' 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, pTab, ROLE_SYSTEM_PAGETAB)
' Click Tab
Call oTab.accDoDefaultAction(ByVal 0&)
' True if OK
SetRibbonTabFocus = True
Exit Function
gestion_erreurs:
SetRibbonTabFocus = False
End Function
' Fonction privée pour rechercher d'un objet accessible à partir de son parent, son role et son nom
Private Function FindChildByRoleOrName(pParent As IAccessible, Optional pChildName As String = "*", Optional pChildRole As String = "*") As IAccessible
Dim lName As String, lRole As Long
Dim oChild As IAccessible
Const NAVDIR_FIRSTCHILD = &H7&
Const NAVDIR_NEXT = &H5&
On Error GoTo gestion_erreurs
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&)
If lRole Like pChildRole And lName Like pChildName Then
Set FindChildByRoleOrName = oChild
Exit Do
End If
Loop
Exit Function
gestion_erreurs:
Set FindChildByRoleOrName = Nothing
End Function |
Partager