none
Updating Ribbon Label at Runtime RRS feed

  • Question

  • Hi guys,

    I got another question related to the ribbon bar I am currently working on:

    The bar is finished and the buttons are linked as well, now I am working on the final issues. My problem is, that there are English and German labels for my ribbon. Everything is stored in the vba code, and there is a "get_language" sub, which is reliant whether the ribbon labels are in English or german. My problem is now, that there are options where I can change the language of the whole menu, but the ribbon only updates when I restart excel. How am I able to tell them to update their labels at runtime?

    The way I wrote may be a bit confusing but I hope u are able to get my point.

    Thanks in advance

    best regards 

    Friday, September 18, 2015 9:26 AM

Answers

  • Hi,

    The ribbon developing is different with command bar. To update the ribbon control at runtime, we need to use callback functions. For example, in this scenario we can add "getLabel" call back for every control we need to update their label. And add a button to change the language, in the button onaction we can invalid the ribbon to make the ribbon's call back executed.

    Here is example which will change the button's label when you click the button for your reference:
    Ribbon XML:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
    	<ribbon startFromScratch="false">
    		<tabs>
    			<tab id="customTab" label="Custom Tab">
    				<group id="customGroup" label="Custom Group">
    					<button id="customButton" getLabel="getLabel" imageMso="HappyFace" size="large" onAction="Callback" />
    				</group>
    			</tab>
    		</tabs>
    	</ribbon>
    </customUI>

    VBA code:

    Dim customRibbon As IRibbonUI
    Dim lanuageContext As String
    'Callback for customUI.onLoad
    Sub OnLoad(ribbon As IRibbonUI)
    Set customRibbon = ribbon
    End Sub
    
    'Callback for customButton getLabel
    Sub getLabel(control As IRibbonControl, ByRef returnedVal)
    If lanuageContext = "English" Then
    
        If control.ID = "customButton" Then
            returnedVal = "English Label"
        End If
    Else
     
         If control.ID = "customButton" Then
            returnedVal = "Chinese Label"
        End If
    End If
    
    End Sub
    
    'Callback for customButton onAction
    Sub Callback(control As IRibbonControl)
    
    If lanuageContext = "English" Then
        lanuageContext = "Chinese"
    Else
        lanuageContext = "English"
    End If
    
    customRibbon.Invalidate
    
    End Sub
    
    
     

    In addition, here are some helpful links for your reference:

    Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)

    Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 21, 2015 6:03 AM
    Moderator

All replies

  • Hi,

    The ribbon developing is different with command bar. To update the ribbon control at runtime, we need to use callback functions. For example, in this scenario we can add "getLabel" call back for every control we need to update their label. And add a button to change the language, in the button onaction we can invalid the ribbon to make the ribbon's call back executed.

    Here is example which will change the button's label when you click the button for your reference:
    Ribbon XML:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
    	<ribbon startFromScratch="false">
    		<tabs>
    			<tab id="customTab" label="Custom Tab">
    				<group id="customGroup" label="Custom Group">
    					<button id="customButton" getLabel="getLabel" imageMso="HappyFace" size="large" onAction="Callback" />
    				</group>
    			</tab>
    		</tabs>
    	</ribbon>
    </customUI>

    VBA code:

    Dim customRibbon As IRibbonUI
    Dim lanuageContext As String
    'Callback for customUI.onLoad
    Sub OnLoad(ribbon As IRibbonUI)
    Set customRibbon = ribbon
    End Sub
    
    'Callback for customButton getLabel
    Sub getLabel(control As IRibbonControl, ByRef returnedVal)
    If lanuageContext = "English" Then
    
        If control.ID = "customButton" Then
            returnedVal = "English Label"
        End If
    Else
     
         If control.ID = "customButton" Then
            returnedVal = "Chinese Label"
        End If
    End If
    
    End Sub
    
    'Callback for customButton onAction
    Sub Callback(control As IRibbonControl)
    
    If lanuageContext = "English" Then
        lanuageContext = "Chinese"
    Else
        lanuageContext = "English"
    End If
    
    customRibbon.Invalidate
    
    End Sub
    
    
     

    In addition, here are some helpful links for your reference:

    Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)

    Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 21, 2015 6:03 AM
    Moderator
  • Thanks for the detailed answer, i'll have a closer look at it.

    Monday, September 21, 2015 9:02 AM