views:

1061

answers:

2

I have an automation add-in written in c# that exposes some functions to be used as formulas in Excel.

The formulas can be successfully used from an Excel sheet but they do not appear in Excel2007's formula autocomplete lists.

i.e. If I want to use the function AddNums(x,y) within an excel sheet then I must know what the function is called or I can find the function in the function wizard. It would be nice to be able to start typing Add.. and then see the formulas beginning with Add displayed.

Is this supported in Excel for automation add-ins? (I know it is for xlls).

+1  A: 

This from Microsoft support :

Automation Add-ins and the Function Wizard Each Automation Add-in has its own category in the Excel Function Wizard. The category name is the ProgID for the Add-in; you cannot specify a different category name for Automation Add-in functions. Additionally, there is no way to specify function descriptions, argument descriptions, or help for Automation Add-in functions in the Function Wizard.

This article also mentions that other addin types take precedence in the formula list.

My prefered approach is to write a VBA addin that wraps up the functionality that you expose in your current addin. I Do this by implementing my code in a COM DLL (That supports IDTExtensibility2 so it loads as a COM addin), and then access other methods on that object via very thin vba wrappers:

Public Function AddinInMethod ( param As String ) As Variant
    Dim oAdd As Object
    On Error GoTo Err
    Set oAdd = Application.COMAddIns.item("MyProgID").Object
    AddInMethod = oAdd.AddInMethod(param)
    Exit Function
Err:
    AddinMethod = "#" & Err.Description
End Function

This works well for me since all my code is C++.

Since you are writing C# code, you might be better off implementing your add in as a C# VSTO add-in. I haven't done this personally, but it looks like there are lots of nice framework features that you can take advantage of as this type of Addin (though you are limited to newer versions of Office).

Cannonade
A: 

I think even in Excel 2007, the functions will be listed. This is what I always see using my UDFs. Here is an example, you may want to have a try. I know for sure it works on my computer.

http://book.greenwich2greenwich.com/Examples/