Microsoft Visio VBA CustomUI Ribbon help – Changing Default Value of EditBox

I have a customUI with an EditBox and want to set the default value when the User opens the Visio template file. Here is the 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>

So I expect BOMLink to have its default text updated through its getText callback function.

Here is my vba code:

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

As it stands right now, I do not get the "CustomRibbonOnLoad called" debug print, but I do get the "Callback UpdateBOMLinkText" called. However the text does not change to the default test text as expected. When I open the document and click the Custom Tab I get this in the debug:

>invokeVBA: ThisDocument.BOM_getText
Callback UpdateBOMLinkText
<invokeVBA: 0x80020009

I am attempting to fill it with "test default text" for now, but in the future want to call upon the Shapesheet and pull data from there to fill by default.

Any help would be appreciated, thanks!



Read more here: https://stackoverflow.com/questions/68488819/microsoft-visio-vba-customui-ribbon-help-changing-default-value-of-editbox

Content Attribution

This content was originally published by adang at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: