Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

How do I change the text of a label control in custom Excel ribbon created with VSTO?

Posted on 2009-07-08
Last Modified: 2013-11-10

I've created a custom tab in Excel ribbon with VSTO, and I'd like to change the text of a label placed in this tab from my add-in code (when user presses the button BtnCHangeWbDest, an input text box may appear and save the value in LblWbDestination).

Would you know how to do that?

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadImage="GetImage">
      <tab id="myTab" label="My Tab">
        <group id="GrpCopySheet" label="Copy sheet">
          <button id="BtnCopySheet" label="Copy current sheet" onAction="CopyCurrentSheet"
                  size="large" screentip="Copy current sheet to a workbook." image="copy_doc_excel"/>
          <labelControl id="Label1" label="Destination workbook:" />
          <labelControl id="LblWbDestination" label="No workbook has been selected"/>
          <button id="BtnChangeWbDest" label="Change workbook" showImage="false" onAction="ChangeWbDest"/>

Open in new window

Question by:JulienVan
  • 2

Accepted Solution

xenacode earned 500 total points
ID: 24812302

To dynamically set the text, you can use the GetLabel attribute of the button instead of the Label attribute and set this to the name of a function in the ribbon class code that returns the label text.

in the xml:
<button id="BtnCopySheet"  GetLabel = "GetMyLabelText"   etc

in the class:
Public Function GetMyLabelText(control As IRibbonControl) As String
End Function

That's a VB example but the C# is fairly similar.


Expert Comment

ID: 24812332
Sorry, just re-read your post. If it's the tab label you want to change, use the GetLabel attribute of the tab.


Author Comment

ID: 24812382
Hi xenacode,

Thanks for your response, it works fine.

Here is a C# example if somebody is look for code snippet: https://blogs.msdn.com/jensha/Default.aspx?p=9 .

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question