【发布时间】:2020-04-12 19:45:31
【问题描述】:
我正在使用 Excel 2010 并尝试在 F# 中运行 Excel-DNA/Samples code 以进行功能区自定义。
<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 -->
Button1 的操作有效,在第 14 行放置断点按预期工作。
但是 Button3 的操作 OnDumpData 没有。我可以看到代码永远不会被调用,因为放置在第 45 行的断点永远不会被命中。
member this.OnDumpData (control:IRibbonControl) =
let app = ExcelDnaUtil.Application :?> Application // line 45. Breakpoint here is never reached.
let cellA1 = app.Range("A1")
我首先认为这可能是版本问题,我尝试将 cutomUI 行 (#26) .../office/2006/01... 替换为 .../office/2009/07...,但问题仍然存在。
我错过了什么(设置或其他东西......)?如何让 Button3 正确触发 OnDumpData 代码?
编辑1: 正如示例文件中所建议的那样,我打开了Excel 选项“显示加载项用户界面错误”选项(在“常规”下的“高级”选项卡下)。我在按下 Button3 时收到的错误消息是:
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.
... 然后我注意到,当我关闭调试 Excel 表时,我在 VS 的输出窗口 ExcelDna.Integration Warning: 1 : Assembly OFFICE could not be loaded from resources. 中收到此消息。这可能是相关的,但我不完全确定在哪里解决这个问题。
【问题讨论】: