In my .dna file I have:
<DnaLibrary Name="First Add-In" RuntimeVersion="v4.0" Language="C#">
<ExternalLibrary Path="MyLibrary.dll" Pack="true"/>
<Image Name="M" Path="M.png" Pack="true" />
<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage'>
<ribbon>
<tabs>
<tab id='CustomTab' label='My 2010 Tab'>
<group id='SampleGroup' label='My Sample Group'>
<button id='Button1' label='My Second Button' image='M' size='normal' onAction='RunTagMacro' tag='ReformatSelection='/>
</group >
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>
</DnaLibrary>
In my .cs file I have:
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;
using System.Windows.Forms;
namespace MyLibrary
{
[ComVisible(true)]
public class Class1 : ExcelRibbon
{
public void ReformatSelection(IRibbonControl control)
{
MessageBox.Show("Hello");
}
}
}
When I load the addin the button and tab appears fine in the Ribbon, but clicking the button does not run the ReformatSelection method. In the example files provided with Excel-DNA all the subs and functions that are hooked to the onAction events are in the .dna file. I am trying to move them out of the .dna file and into the .cs file. What am I doing wrong?
Your signature for ReformatSelection()
is not right for the onAction
handler of a ribbon button.
It should be:
public void ReformatSelection(IRibbonControl control) {...}
You can get a list of all the Office Ribbon callbacks signatures here: http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx