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

5

6

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.

Emcee answered 11/4, 2017 at 23:46 Comment(3)
Since we are not sure about the actual root cause of this issue. I would suggest to add "VSTO_SUPPRESSDISPLAYALERTS" environment variable on computer where issue is reproducible. Set environment variable value to 0. Doing this would help you identify the actual problem if there is any at the loading of Add-in. In other words, the error message would popup right in front.Berard
Roger that, @AzazulHaq. Don't worry, I haven't forgotten about this. I intend to test it as soon as I revisit the project, but that won't be for a few more days. I like the idea of turning on VSTO display alerts though, thank you.Emcee
Encountered the same problem, I found that it was caused by an error in the load event, but not everyone is so, plus try catch to avoid errorsAlvira
S
1

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

Stereotomy answered 19/4, 2017 at 17:37 Comment(2)
Definitely a good idea, although I did try to disable other add-ins. Another note: I do have code in the ribbon.new event that checks active directory to authenticate the current user and then hides any button groups that fail authorization. It takes a few seconds sometimes to connect to the AD.Emcee
Seems worthwhile to look at the AD authentication. If it's the culprit, some refactoring and/or correct placement of ribbon.invalidate might do the trick.Stereotomy
B
1

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
Berniecebernier answered 8/6, 2017 at 13:37 Comment(0)
A
0

I don't think this is a setting issue in Excel. Sometimes buggy behavior like this can get smoked out with some house keeping.

Scan all protected system files and replace corrupted files with a cached copy that is located in a compressed folder at %WinDir%\System32\dllcache. This can take some time, don't interrupt it. Close as many things as possible and from elevated powershell run:

sfc /scannow

If it is a corporate machine, make sure you are on the corp network (VPN if needed). Then run:

gpupdate /force

Set your update server to one that does win updates AND office application updates.

Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false

Run windows updates, Full shutdown, push button startup. See if the issue persists. Consider running Ccleaner as well.

Apocrypha answered 12/4, 2017 at 4:16 Comment(0)
I
0

I know this question is a little older, but this might help others (as myself) that was struggling with this issue until today. I solved this issue adding the following code at the STARTUP event handler of my Addin class:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Globals.Ribbons.MyAddinRibbons.MyMainRibbon.Label = "My Add-in Name";
}

In my case, the "MyMainRibbon.Label" property is still changed during the use of the addin, like when creating new workbooks, worksheets, and so on. But until I forced this property at Add-in Startup, my add-in was always loaded with empty label on main ribbon whenever Excel started, and after creating new workbook (for example) the label was fulfilled. Now, Excel already starts and loads my add-in with the right label.

Inutility answered 10/9, 2019 at 14:50 Comment(0)
H
0

I ran into this due to an exception being thrown from the method I passed to the Load event handler in InitializeComponent. I think the best way to avoid a blank label is to never actually throw an exception from the method called by the Load event handler.

Hunker answered 2/2, 2021 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.