IronShay

Ironing code, geek t-shirts and even presentations!

NAVIGATION - SEARCH

Developing Excel Functions in C# for Excel 2010 64-Bit

Lately I needed to write a small “add-in” for Excel that adds a function written in C# (another case of “when your 4 years of office add-in development experience comes back to haunt you”). Before going ahead with that I searched the web for a quick how-to and ran into this old but still relevant blog post by Eric Carter.

I did everything Eric had described, but every time I tried to add the add-in through the Automation Servers dialog I just couldn’t find it in the list. Trying to locate the file through the Browse button resulted in the next window:

The file you selected does not contain a new Automation Server, or you do not hace sufficient privileges to register the Automation Server.

Such a sweet little message that tells you so much and at the same time tells you nothing at all. How can’t you love developing for Office?

After a couple of hours fighting it with everything I knew (run as admin, installing through a setup project, rewriting everything and more) just when I was ready to throw the laptop out the window and wait for Chrome OS to come out, the brilliant mind of Eran Stiller came up with the question – “maybe it’s related to some 64-32 bit stuff”.

Facepalm. Head-to-desk. Facepalm again. Of course it was related!

As you can understand, I have Excel 2010 64bit installed on my machine. And that’s the root of all my problems. Yes, each and every single one of them.
Anyway, To get the addin working on my machine I had to manually register the DLL using the .NET framework’s 64bit regasm utility. If you also have the same problem, follow the next steps to solve it:

  1. Follow all the steps in Eric Carter’s blog post.
  2. Open the project’s properties and uncheck the “Register for COM Interop” checkbox (I actually don’t think it really matters but just in case).
  3. Rebuild the project.
  4. Open cmd (open Start->Run, type “cmd” and hit Enter).
  5. Navigate to %windir%\Microsoft.NET\Framework64\v4.0.30319
  6. Run: regasm /codebase <path_to_dll>\MyAssembly.dll
    Pay attention to the /codebase switch – without it, it won’t work!

That’s it, you’re done. Your command prompt would look similar to that:

regasming the assembly

[Notice that you’ll get a warning here that the assembly is not signed. If you’re writing a real product, make sure you sign it!]

After that, open Excel and add your DLL again (according to the instructions in Eric’s post). After you do that, try using your functions!

I’m adding my sample project here (which works for me) and its output assembly so you can play with it:

Project (5Kb)
Assembly (4Kb)

Let me know if something isn’t clear or doesn’t work for you.

All the best,
Shay.



Comments (6) -

Thousands of thanks! I finally let it work. Appreciate your helps!
=Peter

Reply

Thanks - I too struggled with this for a couple of hours before stumbling on your solution. Worked like a charm.

Reply

Hey man,
thank you VERY much. Had the same problem minus the 4 years of general experience in the area - speant at least 10 hours trying different examples which all didn't work because of that.

THANK YOU

Reply

Switzerland Maurice Calvert

Many thanks, I was pulling my hair out!

Reply

Thanks a million!

Reply

Marvelous!!!! after searching for many hours you have saved my life! /Codebase did the trick!!

Reply

Add comment