How to Reference text in EditBox in customUI ?

Started by adang, June 23, 2021, 07:54:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

adang

Hi,
I have a customUI ribbon with intent for User to enter a link in an editbox. I would like to be able to store the value of what is entered in that editbox and reference it so that when User clicks a button, they are taken to that url link.

For reference, here is the relevant part of customui xml:
<group
                        id="BOMGroup"
                        label="BOM"
                        autoScale="true"
                        >
                            <editBox id="BOMLink" label="BOM Link:" onChange="BOMLink_onChange"/>
                 
                    <button
                            id="GoToBOMLink"
                            label="Go To BOM Link"
                            screentip="Opens Browser to go to BOM Link"
                            size="large"
                            imageMso="HyperlinkOpenExcel"     
                            onAction="ThisDocument.OpenBOM"
                            />
                </group>


This is the relevant part of vba :
Sub BOMLink_OnChange(control As Office.IRibbonControl, text As String)
    'this callback never gets called
    BOMLinkText = this.BOMLink.text
    Debug.Print "onchange"
End Sub
Public Sub openBOM(ByRef control As Office.IRibbonControl)
    Dim BOMUrl As String
    'below code does not work
    BOMUrl = ThisDocument.CustomUI.CustomTab.BOMGroup.BOMLink
    openUrl (BOMUrl)
    Debug.Print "Here"
    Debug.Print BOMUrl
End Sub


I have not been able to get the onChange callback function to work properly, and cannot figure out how to properly reference the text in the editbox in the customui.

Thanks in advance for any help

Paul Herber

I don't know the answer, but ActiveX controls don't work anything like standard Visio shapes.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Nikolay

#2
You cannot get value from control you define with XML markup, you need to use callbacks (like you do).
For your callback to be called, you need to fully specify it, like you did for the GoToBOMLink: ThisDocument.BOMLink_onChange

Please note that "onChange" handler is called when the control looses focus (i.e. when you have finished editing)
I.e. not when you type a single character, but when you move away for the edit control.

So your code may look something like this:


     <editBox id="BOMLink" label="BOM Link:" onChange="ThisDocument.BOMLink_onChange" />


Dim BOMLinkText

Sub BOMLink_OnChange(control As Office.IRibbonControl, text As String)
    BOMLinkText = text
End Sub

Public Sub openBOM(ByRef control As Office.IRibbonControl)
    ActiveDocument.FollowHyperlink BOMLinkText, ""
End Sub


BTW my Visio version complains about autoScale="true",
maybe it's a new feature available in newer Visio versions.

issati

#3
Thanks nikolay, that works.

This would be useful if it's possible to store a link in the ribbon (you'd also store it in the document shapesheet I guess), how would you go about populating the editbox when the document is reopened? I'm unsure as to how the gettext function would play into this

Cheers,

adang

Wow, thanks Nikolay. What a silly thing for me to miss... but all works as expected now Thanks!