Visio Guy

Visio Discussions => Programming & Code => Topic started by: adang on July 15, 2021, 12:15:19 PM

Title: Changing Default Value of EditBox
Post by: adang on July 15, 2021, 12:15:19 PM
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="" onLoad="CustomRibbonOnLoad">
      <tab id="CustomTab1" label="My Tab">
                            <editBox id="BOMLink" label="BOM Link:" onChange="ThisDocument.BOMLink_onChange" getText = "ThisDocument.BOM_getText"/>
                            label="Go To BOM Link"
                            screentip="Opens Browser to go to BOM Link"

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!