3

Tried to create a ribbon with excel-dna and C#. The ribbon is not displayed in excel when the add-in is loaded.

dna file:

<DnaLibrary Name="falcon" RuntimeVersion="v4.0">
<ExternalLibrary Path="bin/Debug/falcon.dll" />
<!--<Reference AssemblyPath="System.Windows.Forms.dll" />-->

<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='OnLoad'>
  <ribbon>
    <tabs>
      <tab id='CustomTab' label='My Tab' insertAfterMso='View'>
        <group id='SampleGroup' label='My Group'>
          <button id='LoginCmd' onAction='OnLogonPressed' label='logon' />
        </group >
      </tab>
    </tabs>
  </ribbon>
</customUI>
</CustomUI>
</DnaLibrary>

cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using System.Runtime.InteropServices;
using ExcelDna.Integration.CustomUI;

namespace MyLibrary
{
    [ComVisible(true)]
    public class Ribbon : ExcelRibbon
    {
        private IRibbonUI ribbon = null;

        public void OnLogonPressed(IRibbonControl control)
        {
            if (ribbon != null)
            {
                ribbon.InvalidateControl(control.Id);
            }

        }

        public void OnLoad(IRibbonUI ribbon)
        {
            this.ribbon = ribbon;
        }

    }
}

I use Visual Studio Community Edition and the code compiles with .NET 4.6. I load the add-in by clicking directly on the xll file or by loading it in a new excel file. In excel the add-in tab is enabled and the macro security is on the lowest level. Furthermore I enabled under Settings > Advanced the option to show all errors for UI add-in's. I use excel 2010.

When I open excel the ribbon is not shown neither a error message. Anyone any suggestions?

user3188454
  • 76
  • 1
  • 8
  • It works on my machine (though not checked with 4.6 yet), so the ribbon markup and code are correct. I suggest adding a simple UDF (maybe even as a static function in Ribbon) to confirm that the add-in is actually loading. (Macro security settings might prevent it from loading completely). Beyond that, check another computer, if you can, and look through security settings in Excel that might prevent COM add-ins from being loaded. – Govert Jul 31 '15 at 09:00
  • Oh - your Path="..." in the ExternalLibrary looks wrong. Is the .dll not next to the .xll? Maybe start with a new Class Library project, and install the "Excel-DNA" NuGet package. – Govert Jul 31 '15 at 09:01
  • I used the visual studio externalLibrary project and the NuGet package. Afterwards everything worked perfect - I can use the files from the bin folder and F5 to start debugging. thanks for the comments govert! – user3188454 Aug 03 '15 at 09:13

1 Answers1

0

I had similar problem, but it works after I made assembly ComVisible as well:

[<assembly: ComVisible(true)>]
DenisKolodin
  • 13,501
  • 3
  • 62
  • 65