2017-10-11 151 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

相关问题