This should work for Excel and Outlook using C #.
Based on your question, I assume that you can create most of the XML to get the button on the ribbon, so I will skip this part. You also did not mention which event the label button should change, so I assume that clicking this button will change the label text.
First set the XML button code in place
<button id="YourUniqueId" onAction="YourUniqueId_Click" getLabel="GetYourLabelText">
Create a class level variable that will be available to all methods in your tape class before the constructor, and then set the value in the constructor. You will also need a ribbon user interface class variable. This variable should be created when the tape is loaded using the load method in xml, such as onLoad = "Ribbon_Load".
public class Ribbon: Office.IRibbonExtensibility { private bool _buttonClicked; private Office.RibbonUI ribbon; public Ribbon() { _buttonClicked = false; } public void Ribbon_Load(Office.IRibbonUI ribbonUI) { ribbon = ribbonUI; } }
Further in your ribbon class, you will need two classes, YourUniqueId_Click and GetYourLabelText.
public void YourUniqueId_Click(Office.IRibbonControl Control) {
The GetYourLabelText method is launched when the feed is initially loaded into outlook or excel. Since the class variable "_buttonClicked" is set to false in the constructor, the button label will begin as "Button off." Each time a button is clicked, "_buttonClicked" changes the logical state, and then the button is reset, again calling the "GetYourLabelText" method.
source share