Janthelme
Janthelme

Reputation: 999

Excel-DNA, issue with firing Ribbon's onAction code. F#

I am on Excel 2010 and trying to run the Excel-DNA/Samples code for ribbon customization in F#.

<tab id='CustomTab' label='My F# Tab'>
   <group id='SampleGroup' label='My Sample Group'>
        <button id='Button1' label='Run a macro' onAction='RunTagMacro' tag='showMessage' />    <!-- works fine -->
        <button id='Button3' label='Dump the Excel Version to cell A1' onAction='OnDumpData'/>  <!-- DOES NOT WORK -->

The Button1's action works, and placing a break-point on line 14 works as expected.

However Button3's action, OnDumpData, does not. I can see that the code is never called since a break-point placed on line 45 is never hit.

member this.OnDumpData (control:IRibbonControl) =
    let app = ExcelDnaUtil.Application :?> Application  // line 45. Breakpoint here is never reached.
    let cellA1 = app.Range("A1")

I first thought that it might be a versioning issue and I tried to replace the cutomUI line (#26) .../office/2006/01... with .../office/2009/07... but the problem persisted.

What did I miss (a setting or something...)? How can I get the Button3 to fire the OnDumpData code properly?

EDIT1: As suggested in the sample files, I switched-on the Excel Option "Show add-in user interface errors" option (under the Advanced tab under General). The error message I got while pressing on Button3 is :

An exception occurred while calling function "OnDumpDate". Exception message is :
Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

... And then I noticed that when I close the debug Excel sheet, I get this message in VS's output window ExcelDna.Integration Warning: 1 : Assembly OFFICE could not be loaded from resources.. It's probably related but I am not completely sure where to fix the issue.

Upvotes: 0

Views: 332

Answers (1)

Govert
Govert

Reputation: 16907

It sounds like you need to add a reference to the Office.dll assembly in your project. This is only of the COM-related PIA assemblies (like Microsoft.Office.Interop.Excel).

Either add directly to your project, or install the NuGet package called "ExcelDna.Interop" which includes this library and should add a reference too.

Upvotes: 2

Related Questions