我尝试将其设置为禁用自定义按钮,具体取决于Excel功能区上另一个自定义按钮的切换状态。我的丝带中定义了一个按钮' XML如下:
'Callback for ButtonCalc getEnabled
Sub disableRefresh(control As IRibbonControl, ByRef enabled)
If calcState Then
enabled = True
Else
enabled = False
End If
End Sub
getEnabled标记的回调是:
<toggleButton id="ButtonMode" label="Light Mode" size="large" onAction="ToggleCalcClicked" image="Mode" getPressed="checkLight"/>
术语&#34; calcstate&#34;是一个由切换按钮控制的布尔操作:
Public calcState As Boolean
Dim MyRibbon As IRibbonUI
Sub ToggleCalcClicked(control As IRibbonControl, pressed As Boolean)
calcState = Not calcState
Worksheets("Setup").Range("L47").Value = calcState
Call ChangeCalcState
End Sub
这部分的VBA:
{{1}}
一切正常,但重新计算按钮被永久禁用。我做错了什么?
答案 0 :(得分:1)
您必须使控件无效才能更改可见性或启用的属性。
Public calcState As Boolean
Dim MyRibbon As IRibbonUI
Sub ToggleCalcClicked(control As IRibbonControl, pressed As Boolean)
calcState = Not calcState
Worksheets("Setup").Range("L47").Value = calcState
ChangeCalcState
MyRibbon.InvalidateControl("ButtonCalc")
End Sub