RibbonX-Workshop - Jeder Tabelle ein eigenes Tab spendieren

Manchmal ist es erforderlich für jedes Tabellenblatt ein eigenes Register im Menüband zu haben. Wie das funktioniert lernen wir hier.

Im Klassenmodul ThisWorkbook fügen Sie folgenden Code ein.
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  If Not objRibbon Is Nothing Then objRibbon.Invalidate
End Sub


In einem allgemeinen Modul folgenden Code.
Option Private Module
Option Explicit

Public objRibbon As IRibbonUI

Public Sub onLoad_T34(ribbon As IRibbonUI)
  Set objRibbon = ribbon
End Sub

Public Sub getVisible_Tabs(control As IRibbonControl, ByRef returnedValue)
  If ActiveSheet.Name = control.Tag Then returnedValue = 1
End Sub


Public Sub onAction_Eins(control As IRibbonControl)
   MsgBox control.ID
End Sub

Public Sub onAction_Zwei(control As IRibbonControl)
   MsgBox control.ID
End Sub


Der XML-Code lautet wie folgt.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="onLoad_T34">
   <ribbon>
      <tabs>

         <tab id="tab0" label="Tab Eins" tag="Tabelle1" getVisible="getVisible_Tabs" insertBeforeMso="TabHome" >
            <group id="grp0" label="Gruppe Eins">
               <button id="btn0" label="Button 1" imageMso="HappyFace" size="large" onAction="onAction_Eins" />
            </group>
         </tab>

         <tab id="tab1" label="Tab Zwei" tag="Tabelle2" getVisible="getVisible_Tabs" insertBeforeMso="TabHome" >
            <group id="grp1" label="Gruppe Zwei">
               <button id="btn1" label="Button 2" imageMso="AutoDial" size="large" onAction="onAction_Zwei" />
            </group>
         </tab>

      </tabs>
   </ribbon>
</customUI>