0

So, I have created a ribbon in an Excel VSTO addin. This ribbon has labels that I would like to update based on values that are present within workbook cells.

The issue is that the label values are persisting across workbooks - they are not workbook specific.

I have a code that refreshes the labels, and could set it to refresh on change of activate workbook.

The issue with this is where the user has two workbooks open side by side - they will see the same label on both ribbons even though the workbooks should be showing separate values.

Does anyone have any suggestions to solve this? Currently I am setting the label values as so

Globals.Ribbons.CustomRibbon.lblClientCode.Label =

Stu-co
  • 39
  • 7

1 Answers1

0

Regardless of how many workbooks you have opened, there is always only one ribbon object to all of them.

Therefore you should handle the Application.WorkbookActivate event and update your ribbon label text according to the values in the respective workbook.

Heinz Kessler
  • 1,610
  • 11
  • 24
  • I figured that this was the case. It is a static class after all, so that makes sense. Bit of a shame really but never mind. – Stu-co Jan 05 '18 at 13:54
  • It's easy to be fooled by Excel, because it does a great job to pretend two workbooks are two separate instances of Excel. This software design seems t come back from the days of the "MDI" (multiple document interface) design philosophy, when they started with MS Office. – Heinz Kessler Jan 05 '18 at 18:21
  • @Stu-co see also this answer https://stackoverflow.com/a/45282171/3205529 , it may helps – Malick Jan 06 '18 at 12:55