By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Using a C# class file as an Excel Automation add-in

P: n/a
Hi,

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();
}
}

}

Jan 20 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.