我正在尝试使一个切换按钮在Word 2019的功能区中起作用。在堆栈溢出的地方,我已经查看了很多示例,但是我似乎并没有启动并运行它。我的XML定义明确,看起来像:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="loadRibbon">
<ribbon>
<tabs>
<tab id="doc_management" label="Publishing" insertBeforeQ="TabDeveloper">
<group id="doc_drafting" label="Drafting" autoScale="true">
<toggleButton id="toggling" label="Insert Watermark" imageMso="WatermarkGallery" onAction="togglingWatermark" getPressed="buttonPressed"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
相应的VBA代码为:
Option Explicit
Public myRibbon As IRibbonUI
Public isPressed As Boolean
Sub loadRibbon(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub
Sub togglingWatermark(control As IRibbonControl, pressed As Boolean)
Select Case control.ID
isPressed = pressed
Case "toggling"
If isPressed Then
MsgBox isPressed
Else
MsgBox isPressed
End If
End Select
myRibbon.InvalidateControl control.ID
End Sub
Sub buttonPressed(control As IRibbonControl, ByRef returnedVal)
Select Case control.ID
Case "toggling"
returnedVal = isPressed
End Select
End Sub
存在带有相应按钮的自定义标签。我也可以切换按钮。但是我希望切换后会立即看到一个弹出屏幕。那没有发生。我想念什么?任何帮助将不胜感激!
getPressed
回调在Office使Fluent UI控件无效并使您指定是否按下切换按钮控件时调用。要调用回调,您需要使用IRibbonUI.InvalidateControl方法,使功能区用户界面上单个控件的缓存值无效。
您可以通过使用COM加载项中的回调过程来自定义功能区UI。对于该外接程序实现的每个回调,都将缓存响应。例如,如果外接程序编写器为按钮实现getImage
回调过程,则一次调用该函数,然后加载图像,然后如果需要更新图像,则使用缓存的图像而不是调用该过程。 。对于该控件,此过程一直保持不变,直到外接程序使用InvalidateControl
方法表示已缓存的值无效为止,这时,再次调用该回调过程并缓存了返回响应。
此外,getPressed
回调的签名看起来像这样:
Function GetPressed(control As IRibbonControl) As Boolean
它返回一个布尔值,指示按下状态。它不是像onAction
这样的事件处理程序。