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,700 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 a scrolling table in Microsoft Excel using the INDEX function.

770 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