2017-10-11 60 views
1

一直試圖隱藏excel功能區上的自定義控件,並且我的代碼不斷顯示來自我的RefreshRibbon()子項的消息。無論我從HideImport()子傳遞什麼字符串,該控件都將保持可見。我在這裏包括自定義功能區的XML和出現問題的宏。無法隱藏excel功能區上的自定義控件

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
<ribbon startFromScratch="false"> 
    <tabs> 
     <tab id="tabControl1" label="Control"> 
      <group id="grpImport1" label="Import" getVisible="GetVisible" tag="ShowFalse"> 
       <button id="btnDetail" label="Read Detail" image="Ex" size="large" onAction="ReadDetail" /> 
      </group> 
      <group id="grpJourneys1" label="Journeys" getVisible="GetVisible" tag="ShowTrue"> 
       <button id="btnLegAdd" label="Add" image="AddLeg" size="large" onAction="AddLeg" /> 
       <button id="btnLegRemove" label="Remove" image="RemoveLeg" size="large" onAction="RemoveLeg" /> 
       <button id="btnLegRetime" label="Retime" image="RetimeLeg" size="large" onAction="RetimeLeg" /> 
      </group> 
     </tab> 
    </tabs> 
</ribbon> 

Dim ribControl As IRibbonUI 
Public strTag As String 

Sub RibbonOnLoad(ribbon As IRibbonUI) 
    Set ribControl = ribbon 
End Sub 

Sub GetVisible(control As IRibbonControl, ByRef visible) 
    If strTag = "Show" Then 
    visible = True 
    Else 
    If control.Tag Like strTag Then 
     visible = True 
    Else 
     visible = False 
    End If 
    End If 
End Sub 

Sub RefreshRibbon(Tag As String) 
    strTag = Tag 
    If ribControl Is Nothing Then 
    MsgBox "Error, Save/Restart your workbook" 
    Else 
    ribControl.Invalidate 
    End If 
End Sub 

Sub ReadDetail(control As IRibbonControl) 
    MsgBox "This is Read Detail" 
End Sub 

Sub AddLeg(control As IRibbonControl) 
    MsgBox "This is Add Leg" 
End Sub 

Sub RemoveLeg(control As IRibbonControl) 
    MsgBox "This is Remove Leg" 
End Sub 

Sub RetimeLeg(control As IRibbonControl) 
    MsgBox "This is Retime Leg" 
End Sub 

Sub HideImport() 
    Call RefreshRibbon(Tag:="*True") 
End Sub 

通常不會公佈在這裏一如既往地管理你的閱讀迴應其他問題後解決它自己,而是這是推動我瘋了。

回答

0

你沒有回調函數在您的自定義功能區代碼: 例如:<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonOnLoad">

這樣你就不會運行RibbonOnLoad()程序。因此,您沒有設置變量ribControl

+0

非常感謝您的快速響應。在VBA之前使用過的對象和ThoughtLoad是IRibbonUI聲明的一部分。完美的感覺,現在它的作品,我可以修改做我想做的 – Lorne