Search code examples
excelvbaribbonx

Excel 2007 Ribbon


I have a simple Ribbon with a few groups in it.

I need to modify this ribbon through VBA to toggle visibility on the groups that I have in the Ribbon. Let's say Range("A1") has "A" as the cell value; then this group would be visible. If it's empty then it will be hidden.

Here is the XML for that Ribbon, the group I need to toggle is:

<group id="rxGrp_DeveloperTools" label="Developer Tools">

Solution

  • Try this markup for the ribbon group:

    &lt;group id="rxGrp_DeveloperTools" label="Developer Tools" getVisible="rxGrp_DeveloperTools_GetVisible"&gt;
    

    Then use a sub like this one to show/hide the group:

    Sub rxGrp_DeveloperTools_GetVisible(control As IRibbonControl, ByRef bVisible)
    
        Dim sht as Worksheet
        Set sht = ActiveWorkbook.Sheets(1)
    
        If sht.Range("A1").Value = "A" Then
            bVisible = True
        Else
            bVisible = False
        End If
    
    End Sub