I've written the class below and compiled it with the 'Register for COM
Interop' option set to true and I can see the resulting .dll file.
However, I can not successfully pull it into the Add-in list from Excel
Tools Add-in Automation.I tried copying code straight from this official Microsoft link:
http://msdn2.microsoft.com/en-us/library/ms173189.aspx
I have also tried installing the following patch:
http://msdn2.microsoft.com/en-us/library/ms173189.aspx
I am using MS Office Professional 2003 with a complete installation of
Excel, .NET Framework 2.0 and Microsoft Visual C# Express Edition, and
I'd imported the Excel 5.0 Object Library as a project reference.
I'd really appreciate some help as am quite stuck.
Thank you in advance.
Regards,
Schiz
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Text;
namespace CSharpAddIn
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Functions
{
public Functions()
{
}
public double NormDensity(double x)
{
return Math.Exp(-x * x * 0.5) / Math.Sqrt(2 * Math.PI);
}
//Stuff to deal with the registry below
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(
GetSubKeyName(type));
}
[ComUnregisterFunctionAttribute]
public static void UnRegisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(
GetSubKeyName(type), false);
}
private static string GetSubKeyName(Type type)
{
StringBuilder subKeyName = new StringBuilder();
subKeyName.Append(@"CLSID\{");
subKeyName.Append(type.GUID.ToString().ToUpper());
subKeyName.Append(@"}\Programmable");
return subKeyName.ToString();
}
}
}