无效不会隐藏选项卡

时间:2012-12-27 15:11:17

标签: excel vba excel-2007 ribbonx fluent-ribbon

我试图在Office 2007/2010框架中突破我对Fluent Ribbon / RibbonUI系统的理解。

根据我对WPF / Silverlight的XAML设计的了解和理解,我想知道我是否可以动态显示/隐藏下面描述的Office菜单项,似乎我已经有了FUBAR的东西。

请告知我哪里出错,或者我需要进一步发展的地方:

CustomUI.xml

<group id="grpITOfficeMenu"
            label="Office Menu">
    <button id="btnShowOffice"
                label="Show"
                onAction="ShowOfficeTabs"/>
    <button id="btnHideOffice"
                label="Hide"
                onAction="HideOfficeTabs" />
</group>
<group id="grpITContextualTabs"
            label="Contextual Tabs" >
    <button id="btnShowContext" 
                label="Show" 
                onAction="ShowContextualTabs"/>
    <button id="btnHideContext"
                label="Hide"
                onAction="HideContextualTabs"/>
</group>
...
<officeMenu>
    <button idMso="FileNew"
                getVisible="OfficeGetVisible" />
    <button idMso="FileOpen"
                getVisible="OfficeGetVisible" />
</officeMenu>
<contextualTabs>
    <tabSet idMso="TabSetSmartArtTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetChartTools"
                getVisible="ContextualGetVisible"/>
    <tabSet idMso="TabSetDrawingTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPictureTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPivotTableTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetHeaderAndFooterTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetTableToolsExcel"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPivotChartTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetInkTools"
                getVisible="ContextualGetVisible" />
</contextualTabs>

VBA:

'Method to Refresh the RibbonUI object
Sub RefreshRibbon(tag As String)
   'Check if Ribbon variable has been initialized with Ribbon Object from Excel
   If Not (Rib Is Nothing) Then
      'Ribbon variable has been initialized.
      MyTag = tag
      Rib.Invalidate
   End If
End Sub
'Flip OfficeMenu Tabs visible based on @OffVisible value
Sub OfficeGetVisible(control As IRibbonControl, ByRef returnVal)
   returnVal = OffVisible
End Sub
'Flip Contextual Tabs visible based on @ContVisible value
Sub ContextualGetVisible(control As IRibbonControl, ByRef returnVal)
   returnVal = ContVisible
End Sub
...
'Show/Hide ContextualTabs in the IT Mode
Sub ShowContextualTabs(Optional ctrl As Variant)
   ContVisible = True
   RefreshRibbon tag:=MyTag
End Sub
Sub HideContextualTabs(Optional ctrl As Variant)
   ContVisible = False
   RefreshRibbon tag:=MyTag
End Sub
'Show/Hide OfficeMenu Tabs in the IT Mode
Sub ShowOfficeTabs(Optional ctrl As Variant)
   OffVisible = True
   RefreshRibbon tag:=MyTag
End Sub
Sub HideOfficeTabs(Optional ctrl As Variant)
   OffVisible = False
   RefreshRibbon tag:=MyTag
End Sub

更新

进行了一些详细测试并且技术上有效,但我最终尝试完成的是能够在功能区中显示/隐藏Home, Insert, Page Layout, Formulas, Data, Review, View, Developer, etc.标签。我正在尝试删除startfromscratch元素中customui属性的必要性或必要性。

2 个答案:

答案 0 :(得分:2)

解决了,必须查看idMso&amp;的所有TabSets值。功能区中的Tab个对象。

所以这里是CustomUI的XML,允许显示/隐藏一些默认(至少我需要的)Tab / TabSet&#39; s。使用上面相同的显示/隐藏方法。

<customUI onLoad="s_UIOnLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <!-- Excel File Menu options, not available through Tab or TabSets -->
    <officeMenu>
      <button idMso="FileNew" getVisible="OfficeGetVisible" />
      <button idMso="FileOpen" getVisible="OfficeGetVisible" />
    </officeMenu>
    <!-- Excel TabSets that only become visible when certain objects
    are selected (such as ListObjects, PivotTables, Charts, etc) -->
    <contextualTabs>
      <tabSet idMso="TabSetChartTools" getVisible="ContextualGetVisible"/>
      <tabSet idMso="TabSetDrawingTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetEquationTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetHeaderAndFooterTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetInkTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPictureTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPivotChartTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPivotTableTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSlicerTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSmartArtTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSparkline" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetTableToolsExcel" getVisible="ContextualGetVisible" />
    </contextualTabs>
    <tabs>
      <!-- Excel Menu Tabs, these are not included in the TabSets and
    must be explicitely defined -->
      <tab idMso="TabAddIns" getVisible="OfficeGetVisible" />
      <tab idMso="TabBackgroundRemoval" getVisible="OfficeGetVisible" />
      <tab idMso="TabData" getVisible="OfficeGetVisible" />
      <tab idMso="TabDeveloper" getVisible="OfficeGetVisible" />
      <tab idMso="TabFormulas" getVisible="OfficeGetVisible" />
      <tab idMso="TabHome" getVisible="OfficeGetVisible" />
      <tab idMso="TabInsert" getVisible="OfficeGetVisible" />
      <tab idMso="TabPageLayoutExcel" getVisible="OfficeGetVisible" />
      <tab idMso="TabReview" getVisible="OfficeGetVisible" />
      <tab idMso="TabView" getVisible="OfficeGetVisible" />
      ...
    </tabs>
  </ribbon>
</customUI>

答案 1 :(得分:0)

从Scratch开始

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon  startFromScratch="true"/>
</customUI>
除了后台之外,它除去了所有东西。

如果你想带回一些

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon  startFromScratch="true">
    <tabs>
      <tab idMso="TabView" visible="true"/>
    </tabs>
  </ribbon>
</customUI>