Option Explicit
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] VBA7 Then
Private Declare PtrSafe Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
Private Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
Private oCol As New Collection
Private Sub UserForm_Initialize()
Const CHILDID_SELF = 0&
Dim vElement As Variant, oIaccList() As IAccessible
oIaccList = GetRibbonTabsList
For vElement = 0 To UBound(oIaccList)
Me.ListBox1.AddItem oIaccList(vElement).accName(CHILDID_SELF)
oCol.Add oIaccList(vElement)
Next
End Sub
Private Sub ListBox1_Change()
Call oCol(ListBox1.ListIndex + 1).accDoDefaultAction(0&)
End Sub
Private Function GetRibbonTabsList() As Variant
Const CHILDID_SELF = 0&
Const NAVDIR_FIRSTCHILD = &H7
Const NAVDIR_NEXT = &H5
Const STATE_SYSTEM_INVISIBLE = &H8000&
Dim oIacc As Office.IAccessible, oIaccFilteredArray() As Office.IAccessible
Dim i As Long, k As Long
Set oIacc = Application.CommandBars("Ribbon")
For i = 0 To 6
Set oIacc = oIacc.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
Next i
For i = 0 To 7
Set oIacc = oIacc.accNavigate(NAVDIR_NEXT, CHILDID_SELF)
Next i
Set oIacc = oIacc.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
ReDim oIaccChildrenArray(oIacc.accChildCount - 1)
Call AccessibleChildren(oIacc, 0, oIacc.accChildCount - 1, oIaccChildrenArray(0), 1)
For i = LBound(oIaccChildrenArray) To UBound(oIaccChildrenArray) - 1
If ((oIaccChildrenArray(i).accState(CHILDID_SELF) And (STATE_SYSTEM_INVISIBLE)) = 0) Then
ReDim Preserve oIaccFilteredArray(k)
Set oIaccFilteredArray(k) = oIaccChildrenArray(i)
k = k + 1
End If
Next i
GetRibbonTabsList = oIaccFilteredArray
End Function