Skip to Content

First Excel UDF written in C# using .NET

Eric Carter's article Writing user defined functions for Excel in .NET offers a fantastic introduction to developing UDFs in C# for Microsoft Excel using Automation Add-ins.

Being new to C# development, it was natural that I might encounter a couple of snags while attempting to implement Eric's solution. The first was the generation of a GUID. In his article, Eric states that this may be done using Generate GUID in the Tools menu of Visual Studio. The problem is that this option is not available in the Tools menu of Visual C# 2008 Express Edition. Fortunately generating GUIDs is fairly trivial. The GUID generated using Somocon's Generate GUID Online utility worked perfectly.

The second snag encountered was while attempting to reference the Primary Interop Assemblies for Office 2007. For some reason these libraries are not included in (my installed version of) Visual C# 2008 Express Edition's list of available .NET/COM references. Fortunately adding the required Microsoft.Office.Interop.Excel reference was simply a case of using the Add Reference -> Browse option and then supplying the full Windows path to the DLL. On my Windows XP machine this path looks like this:
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\12.0.0.0__[16-byte hexidecimal number]\Microsoft.Office.Interop.Excel.dll

It is clear that the .NET framework offers a great deal more development potential than VBA. That said, VBA still has its place within the Microsoft Office suite akin to batch files which are still supported by Microsoft Windows operating systems.