【问题标题】:Microsoft Visio VBA CustomUI Ribbon help - Changing Default Value of EditBoxMicrosoft Visio VBA CustomUI 功能区帮助 - 更改 EditBox 的默认值
【发布时间】: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


【解决方案1】:

您需要删除此行,因为它会覆盖您之前在该行中设置的值。

'Callback for BOMLink getText
Sub BOM_getText(control As IRibbonControl, ByRef returnedVal)
    Debug.Print "Callback UpdateBOMLinkText"
    ' MyRibbon.InvalidateControl ("BOMLink") ' <<<< remove this line
    returnedVal = "test default text"
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多