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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

757 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

19 Experts available now in Live!

Get 1:1 Help Now