Reputation: 577
i'm trying to create a User Defined Function for MS Excel in C#.
But no matter what I try, when I try to add the Add-in to Excel I always get the infamous "The file you have selected does not contain a new automation server, or you do not have sufficient privileges to register the automation server" error.
Here's the code that I took from and online example just to try it out:
// C#
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace AutomationAddin
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyUdf
{
public MyUdf()
{
}
public double addMeTest(double x, double y)
{
return x + y;
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(
"CLSID\\{" + t.GUID.ToString().ToUpper() +
"}\\Programmable");
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(
"CLSID\\{" + t.GUID.ToString().ToUpper() +
"}\\Programmable");
}
}
}
I tried this with MS Visual Studio 2012 on Excel 2013 x64 and Excel 2010 x86
SolutionsI've found and tried with no success:
So please guys, if you can tell me what am I missing here and maybe even tell me what should I do to make it work I would be so grateful! Thanks in advance!
I will gladly provide any additional info if needed.
P.S. Haven't had any sleep for two nights now so I might be screwing something up in a really stupid way. If someone could test this code if it works and tell me their project setup it just might help.
Upvotes: 4
Views: 528
Reputation: 14419
You can try this library https://exceldna.codeplex.com, it simplifies creation of UDFs a lot.
Upvotes: 2