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,981 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

630 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