excel dna C# project won't load in excel 2010

Aug 8, 2013 at 7:08 PM
Edited Aug 8, 2013 at 7:09 PM
I am trying to make a UDF in Excel 2010. Currently I have a Excel add in project in Visual Studios 2012 that works great. The UDF would be a fuction in my VS project that I created. I have not been successful in finding a way that works so now I am trying the Excel-DNA way. I created a brand new project that was a class library. Then I added in Excel-DNA through the managed NuGet packages. I followed the steps to make a simple function like =HelloDna("your name") in the notes that came with it.

The only problem is that when I load the simple project it does not load into excel properly. The first message I get is a Microsoft Office security notice saying that there is no digital signature available. It gives me the option to enable this add on or leave it disabled. If I leave it disabled it of course does not work. If I click enable this add-in for this session only I get another warning saying "

The file you are trying to open, 'TestingDNA-AddIn.xll', is in a different format than the specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

Clicking yes attempts to open it but it just comes out like the matrix with all characters BUT A-Z and 1-9. (there should be nothing in any cell in the first place)

Thank you in advance, I might end up making an RTD server if its a better choice than creating a UDF.
Coordinator
Aug 8, 2013 at 7:19 PM
Edited Aug 8, 2013 at 7:20 PM
Hi Andre,

The most likely cause of the 'file in a different format' message is that you have the 64-bit version of Excel, and you are trying to load the 32-bit version of the ExcelDna.xll. You can check your Excel version according to the instructions here: http://office.microsoft.com/en-za/support/am-i-running-32-bit-or-64-bit-office-HA010361023.aspx

By default the NuGet package sets things up for the 32-bit Excel. The "Troubleshooting" section in the NuGet Readme.txt file describes how to fix this for 64-bit:
  • If Excel starts but you get a message saying "The file you are trying to open, [...], is in a different format than
    specified by the file extension.", then you have the 64-bit version of Excel installed. Change the Post-Build
    command line to copy the file "ExcelDna64.xll" to the output directory instead of "ExcelDna.xll".
If you are not running the 64-bit version of Excel and you are getting this message, please write back and we can explore further.

Regards,
Govert
Aug 8, 2013 at 7:36 PM
Okay that makes it load properly! I at first didn't know what the Post-Build command line was, school forgot to mention that one!

It is out of your hands for the security warning correct?

"Microsoft Office security notice saying that there is no digital signature available."

I still get that one, than clicking enable this time only it loads properly.

Thanks again!
Coordinator
Aug 8, 2013 at 7:43 PM
The security stuff is just how Excel works.

You can change Excel's macro security settings to a lower level, then it won't prompt every time.
Later on you can sign your add-in with a certificate for distribution, if appropriate for you.

-Govert
Aug 8, 2013 at 7:45 PM
Again Thank you for your help, I am excited to see how Excel DNA works!
Aug 8, 2013 at 8:36 PM
Edited Aug 8, 2013 at 8:38 PM
Things worked great when it was in its own project, is it possible to have in inside my Excel Add-in project? This way I can have UDF in my Excel Add-in project.

I get an error saying the ExcelDna.Intergration.dll must be strong signed in order to be marked as a prerequisite
Coordinator
Aug 8, 2013 at 8:43 PM
No, the UDFs can't be in a VSTO or COM add-in project.

However, the Excel-DNA project can contain macros, ribbon extensions etc.

You can also load the .xll add-in automatically from your add-in project by calling Application.RegisterXLL(...).

-Govert