Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-08
3
Medium Priority
?
3,228 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
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 demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

783 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