Preserve value in xml ribbon edit box when workbook is saved

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This is my xml code to add a custom ribbon and an edit box:

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
  <ribbon startFromScratch="true">  
    <tabs> 
      <tab id="CustomTab" label="My Tab"> 
        <group id="Group1" label="MyGroup"> 
          <editBox id="MyEditBox" 
                   label="enter text" 
                   onChange="EditBox_OnChange"/> 
        </group> 
      </tab> 
    </tabs> 
  </ribbon> 
</customUI>

What I want is if I put a value, say 10 into the edit box, then save and close the workbook, the next time I open the workbook, I want the value of 10 to remain in the edit box.

Is that possible?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Only if you save it somewhere and then read it back in using the onLoad callback.
 
Upvote 0
Only if you save it somewhere and then read it back in using the onLoad callback.
You mean if the user puts in a value into the edit box, that value needs to be saved somewhere in the workbook and then upon opening the workbook, the Workbooks_Open event gets fired and assigns that value into the edit box?

If so, can you show me some code to do that?
 
Upvote 0
No, not quite. It needs to be saved somewhere (doesn't have to be in the workbook necessarily, though that probably makes most sense) but you need the ribbon's onLoad procedure not the Workbook open event. You don't appear to have that set up in your example, so you'll need to add it. You will also need a getText callback for the editbox so that you can set the value. The onload will need to invalidate the control so that it calls the getText to assign the value to the control. I'm afraid I don't have time currently to put together an example of all of that, but that should be enough terms to search for. ;) (e.g. here)
 
Upvote 0
No, not quite. It needs to be saved somewhere (doesn't have to be in the workbook necessarily, though that probably makes most sense) but you need the ribbon's onLoad procedure not the Workbook open event. You don't appear to have that set up in your example, so you'll need to add it. You will also need a getText callback for the editbox so that you can set the value. The onload will need to invalidate the control so that it calls the getText to assign the value to the control. I'm afraid I don't have time currently to put together an example of all of that, but that should be enough terms to search for. ;)
Thanks, I'll give it a try.

I do know what you mean by onLoad, I think!

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
         onLoad="Initialise">

and in VBA:

Code:
Dim MyRibbon As IRibbonUI

Public Sub Initialise(ByRef ribbon As IRibbonUI)

    Set MyRibbon = ribbon

End Sub
 
Upvote 0
Yes - I just added a link to my previous post that may be useful.
 
Upvote 0
EDIT SORTED:

vba code:

Code:
Option Explicit

    Dim MyRibbon As IRibbonUI
    
    Dim abc
    
Public Sub Initialise(ByRef ribbon As IRibbonUI)

    abc = Sheet1.Cells(1, 1).Value2
    
    Set MyRibbon = ribbon
    
    Call UpdateEditBox
    
End Sub

Sub EditBox_OnChange(control As IRibbonControl, text As String)

    Sheet1.Cells(1, 1).Value2 = text
    
    Call UpdateEditBox

End Sub

Private Sub EditBox_getText(ByRef control As IRibbonControl, _
                          ByRef returnedVal)
    
    returnedVal = abc
    
End Sub

Private Sub UpdateEditBox()
    
    MyRibbon.InvalidateControl "EditBox"

End Sub

xml code:

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
         onLoad="Initialise"> 
  <ribbon startFromScratch="false">  
    <tabs> 
      <tab id="CustomTab" label="My Tab"> 
        <group id="Group1" label="MyGroup"> 
          <editBox id="EditBox" 
                   label="enter text" 
                   onChange="EditBox_OnChange"
             getText="EditBox_getText"/>

        </group> 
      </tab> 
    </tabs> 
  </ribbon> 
</customUI>
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top