Read Values of ChartElementSelector dropdown in the ribbon

14 Views Asked by At

How to read Values of ChartElementSelector dropdown in the ribbon. I am using below code Sub ReadChartElementDropdown() Dim menuBar As CommandBar Dim formatMenuItem As CommandBarControl Dim chartElementMenuItem As CommandBarControl Dim submenuItem As CommandBarPopup

' Get the Menu Bar command bar
Set menuBar = Application.CommandBars("Menu Bar")

' Find the "Format" menu item
Set formatMenuItem = menuBar.FindControl(Id:=30006)

If Not formatMenuItem Is Nothing Then
    ' Check if it's a dropdown menu
    If TypeOf formatMenuItem Is CommandBarPopup Then
        Set submenuItem = formatMenuItem
        
        ' Find the "Chart Elements" submenu item
        For i = 1 To submenuItem.Controls.Count
        
        Set chartElementMenuItem = submenuItem.Controls(i) ' FindControl(Id:=10028)
        MsgBox (chartElementMenuItem.Caption)
        Next
        If Not chartElementMenuItem Is Nothing Then
            ' Check if it's a dropdown menu
            If TypeOf chartElementMenuItem Is CommandBarComboBox Then
                Set submenuItem = chartElementMenuItem
                
                ' Loop through each submenu item
                For Each submenuItem In submenuItem.Controls
                    ' Print the caption of the submenu item
                    Debug.Print submenuItem.Caption
                Next submenuItem
            End If
        End If
    End If
End If

End Sub

I am not able to find correct ID to be used here

Trying to get value of dropdown of inbuild MSo control

0

There are 0 best solutions below