无法隐藏 excel 功能区上的自定义控件
Cannot hide custom control on excel ribbon
一直在尝试隐藏 excel 功能区上的自定义控件,我的代码一直显示来自我的 RefreshRibbon() 子程序的消息。无论我从 HideImport() 子传递什么字符串,该控件都保持可见。我在这里包括自定义功能区的 XML 和有问题的宏。
<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
通常不会在这里发布,因为总是在阅读您对其他问题的回复后设法自己解决,但这让我很生气。
您的自定义功能区代码中没有回调函数:
示例:<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonOnLoad">
所以你不是 运行 RibbonOnLoad()
程序。因此,您没有设置变量 ribControl
一直在尝试隐藏 excel 功能区上的自定义控件,我的代码一直显示来自我的 RefreshRibbon() 子程序的消息。无论我从 HideImport() 子传递什么字符串,该控件都保持可见。我在这里包括自定义功能区的 XML 和有问题的宏。
<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
通常不会在这里发布,因为总是在阅读您对其他问题的回复后设法自己解决,但这让我很生气。
您的自定义功能区代码中没有回调函数:
示例:<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonOnLoad">
所以你不是 运行 RibbonOnLoad()
程序。因此,您没有设置变量 ribControl