【发布时间】:2021-07-22 16:56:05
【问题描述】:
我有一个带有 EditBox 的 customUI,并希望在用户打开 Visio 模板文件时设置默认值。 这是customUI xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="CustomRibbonOnLoad">
<ribbon>
<tabs>
<tab id="CustomTab1" label="My Tab">
<group
id="BOMGroup"
label="BOM"
autoScale="true"
>
<editBox id="BOMLink" label="BOM Link:" onChange="ThisDocument.BOMLink_onChange" getText = "ThisDocument.BOM_getText"/>
<button
id="GoToBOMLink"
label="Go To BOM Link"
screentip="Opens Browser to go to BOM Link"
size="large"
imageMso="HyperlinkOpenExcel"
onAction="ThisDocument.OpenBOM"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
所以我希望 BOMLink 通过其 getText 回调函数更新其默认文本。
这是我的 vba 代码:
Dim MyRibbon As IRibbonUI
Sub CustomRibbonOnLoad(ribbon As IRibbonUI)
Set MyRibbon = ribbon
Debug.Print "CustomRibbonOnLoad called"
MyRibbon.InvalidateControl ("BOMLink") ' Invalidates the cache of a single control
End Sub
Sub myFunction()
MyRibbon.InvalidateControl ("BOMLink") ' Invalidates the cache of a single control
End Sub
'Callback for BOMLink onChange
Sub BOMLink_onChange(control As IRibbonControl, text As String)
End Sub
'Callback for BOMLink getText
Sub BOM_getText(control As IRibbonControl, ByRef returnedVal)
Debug.Print "Callback UpdateBOMLinkText"
MyRibbon.InvalidateControl ("BOMLink") ' Invalidates the cache of a single control
returnedVal = "test default text"
End Sub
'Callback for GoToBOMLink onAction
Sub OpenBOM(control As IRibbonControl)
Debug.Print "Callback OpenBOM"
End Sub
就目前而言,我没有得到“调用CustomRibbonOnLoad”的调试打印,但确实得到了调用的“回调UpdateBOMLinkText”。但是,文本不会按预期更改为默认测试文本。 当我打开文档并单击自定义选项卡时,我在调试中得到了这个:
>invokeVBA: ThisDocument.BOM_getText
Callback UpdateBOMLinkText
<invokeVBA: 0x80020009
我现在尝试用“测试默认文本”填充它,但将来想调用 Shapesheet 并从那里提取数据以默认填充。
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
如果将
ThisDocument.BOM_getText更改为BOM_getText会发生什么?
标签: vba customization visio