Add user defined function to Visual Studio Excel Add-in

后端 未结 4 2157
长发绾君心
长发绾君心 2021-01-04 08:45

In visual studio I have an Excel 2010 Add-in project. How can I have that project create the following module:

\

4条回答
  •  暖寄归人
    2021-01-04 08:54

    A VSTO addin can't create UDF's, so you need to create a separate addin for the functions. Although this addin can be in the same DLL as the VSTO addin, you cannot communicate between the VSTO and the UDF's without special trickery.

    I have a blog post about this. It gives you a complete example project that includes VSTO and UDF's.

    Here is the basic structure of the UDF itself.

    [Guid("3B81B6B7-3AF9-454F-AADF-FAF06E5A98F2")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComVisible(true)]
    public interface IFunctions
    {
        int MYINT();
    }
    
    [Guid("F58C591D-A22F-49AD-BC21-A086097DC26B")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    public class Functions : IFunctions 
    {
        public int MYINT()
        {
            return 42;
        }
    }
    

提交回复
热议问题