I am very new to using Excel DNA, I started using it after I as asked to create some custom funcitons for Excel. But I didn't want to code it in VBA. So I have created my first custom function and now I am needing to add a ribbon bar command
button to work with that function.
I am using Visual Studio 2010 Pro, and I have UAC disabled and I run as the Admin.
Here is my FirstAddIn.dna code:
<DnaLibrary Name="GL Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="MyLibrary.dll" />
<tab id="customTab" label="General Ledger" insertAfterMso="TabHome">
<group id="Refresh" label="Refresh">
<button id="RefreshCmd" label="Reload Data" imageMso="QueryMakeTable" onAction="RefreshCmd" />
And here is my C# code :
using Excel = Microsoft.Office.Interop.Excel;
public class MyRibbon : ExcelRibbon
public void RefreshCmd(IRibbonControl control)
//Excel.Application xlApp = (Excel.Application)ExcelDnaUtil.Application;
public class MyFunctions
[ExcelFunction(Description = "GL Summary")]
public static Double ACT(String Year, String Period, String OU_ID, String Account)
Double Amnt = 0;
parYear = new Parameter("Year", Year);
parPerd = new Parameter("Period", Period);
parOUID = new Parameter("OU_ID", OU_ID);
parAcct = new Parameter("Account", Account);
foreach (Criteria c in parYear)
yr = Years.Instance.Year(Convert.ToInt16(c.Par1));
flt = parPerd.Filter;
flt += " AND " + parOUID.Filter;
flt += " AND " + parAcct.Filter;
foreach (DataRow r in yr.Trial_Balance_Data.Select(flt))
Amnt += Convert.ToDouble(r["Amount"]);
The MyRibbon Class is where I am just testing to see if my RefreshCmd works or not.
But the issue is that I don't even have the custom ribbon bar showing.
Any help with this would be great, once I have these basic items outof the way I can start creating the rest of my project.
Oct 9, 2012 at 5:48 PM
The class derived from ExcelRibbon needs to be 'COM Visible'. You can ensure this either by:
- Marking the class with the [ComVisible(true)} attribute, or
- Ensuring the assembly-wide default is set to [assembly(ComVisible(true)] in the Properties\AssemblyInfo.cs file.
The default C# library project in Visual Studio sets the assembly-wide attribute to [assembly:ComVisible(false)]. There is a project property that also sets this - be sure to set
'COM Visible' to true, but keep 'Register for COM Interop' to
For the code in the .dna file examples this is not a problem, since the .NET default (if there are no attributes) is to make types visible to COM. It's just the Visual Studio template that has the opposite default, and forces you to change or override something.
There are other reasons why your ribbon might not load:
- An error in the .xml,
- your add-in is disabled by Excel - check under File->Options->Add-Ins->Manage: Disabled Items.
- there was an issue with UAC and admin that I fixed in recent check-ins, but I think this affects the case where UAC is enabled, and you explicitly run Excel as an admin.
Write back if you need some more ideas to try.
Thanks that resolved my issue changing the assembly COM Visible to true.