Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET VSTO - Excel ribbon tab label is blank, but only on first instance of Excel

So I am a moderately seasoned VSTO developer, but I am having a new issue with one of my add-ins. The add-in installs and runs just fine, but for whatever reason, when the first instance of Excel is opened (as in, there are no other workbooks currently open), the add-in's ribbon tab label is blank (see below).


enter image description here


To be clear, this problem only appears on the first instance of Excel. If I open another workbook using Ctrl+N or File-->New, the label appears fine on the new workbook (although the first workbook will still show a blank label). Also, before anyone asks, the ribbon tab type is set to Custom, not Office.

To make matters worse, I can't reproduce the problem on my computer, only on the customer's computers. Has anyone seen or heard of this issue before? If so, a link would help out tremendously.


UPDATE

So I resolved the issue, but I'm still not 100% sure how. There was an error in the ribbon's load event that I wasn't handling well, and it somehow short-circuited the label. I made some changes to the handling of that error (and also fixed the error), and now the label appears correctly.


ANOTHER UPDATE

The issue has returned. Any ideas? I'll add a bounty for encouragement.

like image 762
Ross Brasseaux Avatar asked Apr 11 '17 23:04

Ross Brasseaux


2 Answers

It's possible that the issue you describe is being caused by the load order of the VSTO add-ins on the customer's computers. I've seen wacky issues before wherein an Excel add-in during its load stepped on the one following it. This would explain why you can't recreate the issue on your computer (different add-ins and/or add-in load order) and why a second worksheet would not exhibit the issue (the offending add-in is already loaded and so is not creating a process that is blocking your add-in's initial ribbon label display).

Here are a couple of things you may want to try:

  • Call the Invalidate method during the Workbook.New event to see if refreshing the ribbon after all the add-ins are loaded resolves the issue.

    IRibbonUI.Invalidate

    Workbook.New Event

    Alternatively, if the above does not work, it might be interesting to see if closing the initial blank workbook immediately followed by opening a new blank workbook upon initial launch redraws the label.

  • Change the load order on the customer's computers by changing your add-in to load on demand and then creating a second add-in that calls your add-in after it has loaded (thus eliminating the possible interference from another process).

    Change the Load Order of COM Add-ins in Excel

like image 59
joeschwa Avatar answered Sep 28 '22 07:09

joeschwa


Here is how I solved this issue:

  1. Quit Excel
  2. Set the LoadBehavior value to 16 (Load first time, then load on demand) in HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\MyExcelAddIn
  3. Delete %LocalAppData%\Microsoft\Office\Excel*.customUI file(s) as instructed at Where is VSTO add-in's ribbon cached?
  4. Relaunch Excel
like image 30
0xced Avatar answered Sep 28 '22 09:09

0xced