Solved

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

Posted on 2009-07-08
3
2,651 Views
Last Modified: 2013-11-10
Hi,

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?

Thanks
<?xml version="1.0" encoding="utf-8" ?>

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadImage="GetImage">

  <ribbon>

    <tabs>

      <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"/>

        </group>

      </tab>

    </tabs>

  </ribbon>

</customUI>

Open in new window

0
Comment
Question by:JulienVan
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
xenacode earned 500 total points
ID: 24812302
Hi,

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
etc
End Function

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

Pete
0
 
LVL 6

Expert Comment

by:xenacode
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.

Pete
0
 
LVL 2

Author Comment

by:JulienVan
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 .
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

895 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now