title: Hide individual custom ribbon buttons
body: <p>I have an custom excel ribbon and an excel add-in that contains a class which is instantiated once on opening a workbook. Based on some attributes of the class I need certain buttons from the custom ribbon (all in the same tab) to be hidden.</p>
  
  <p>My custom ribbon is:</p>
  
  <pre><code>&lt;customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="loadCustom"&gt;
  &lt;ribbon&gt;
  &lt;tabs&gt;
  &lt;tab id="tab1" label="customTab" getVisible="GetVisible" tag="myTab"&gt;
  &lt;group id="grp1" label="Group1" imageMso="ViewFullScreenView" getVisible="GetVisible"&gt;
      &lt;button id="Bt1" size="large" label="Button1" imageMso="AccessListIssues" onAction="runBt1" visible="true"/&gt;
      &lt;button id="Bt2" size="large" label="Button2" imageMso="AccessListTasks" onAction="runBt2" visible="true"/&gt;
      &lt;button id="Bt3" size="large" label="Button3" imageMso="ControlLayoutStacked" onAction="runBt3" visible="true"/&gt;
      &lt;button id="Bt4" size="large" label="Button4" imageMso="ControlLayoutTabular" onAction="runBt4" visible="true"/&gt;
  
  &lt;/group&gt;
   &lt;/tab&gt;
  &lt;/tabs&gt;
  &lt;/ribbon&gt;
  &lt;/customUI&gt;
  </code></pre>
  
  <p>I then have the following VBA macros in a module to load the custom ribbon and/or disable it:</p>
  
  <pre><code>Public Sub loadCustom(ribbon As IRibbonUI)
  
      Set RibUI = ribbon
  
      If workbookTitle = "myWorkbook" Then
          MyTag = "show"
      Else
          MyTag = False
          RefreshRibbon MyTag
      End If
  
  End Sub
  
  Sub GetVisible(control As IRibbonControl, ByRef visible)
  
      If MyTag = "show" Then
          visible = True
      Else
          If control.Tag Like MyTag Then
              visible = True
           Else
              visible = False
          End If
      End If
   End Sub
  
  Sub RefreshRibbon(Tag As String)
      MyTag = Tag
      If RibUI Is Nothing Then
          MsgBox "Error, Save/Restart your workbook"
      Else
          RibUI.Invalidate
      End If
  End Sub
  </code></pre>
  
  <p>In my specific workbook that the ribbon should load for I have a hidden sheet from which my class module class reads a value for each button to determine whether it should show or not. Once I've read this value how can I hide an individual button? All the examples I've found only seem to work for tabs. Could I pass the ribbonUI to the class and loop through each control? I haven't been able to find a method for doing this. Thanks for any help!</p>