ExcelDna未在AddIn

时间:2018-02-02 17:59:58

标签: vb.net visual-studio-2017 excel-2013 excel-dna

我正在将旧的dna文件转换为visual basic .net,以便在Excel 64位中使用

功能区用于显示32位版本(一个简单的msgbox更改默认值),但功能区未显示在新版本中。

我正在使用VS 2017。

用于创建功能区的代码:

' Can make a class that implements ExcelDna.Integration.CustomUI.ExcelRibbon
' to get full Ribbon access.
Public Class MyRibbon
    Inherits ExcelRibbon

    Public Sub OnButtonPressed(control As IRibbonControl)
        SetDefault()
    End Sub

End Class

功能区的dna文件中的代码:

<CustomUI>
   <!-- Inside here is the RibbonX xml passed to Excel -->
   <customUI xmlns = "http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
      <tabs>
        <tab idMso = "TabAddIns" >
          <group idQ="x:ORSErlang64" label="ORSErlang64">
            <button id="C1" label="Set Default" size="large"
            imageMso="StartAfterPrevious" onAction="OnButtonPressed"/>

          </group>
        </tab>
      </tabs>
    </ribbon>
  </customUI>
</CustomUI>

我无法弄清楚我做错了什么,我在网上找到的大多数例子都是c#,而不是vb.net

1 个答案:

答案 0 :(得分:2)

问题是您要将组的ID声明为idQ="x:ORSErlang64",但您没有声明命名空间x是什么。

customUI元素上,您需要定义x名称空间,例如<customUI xmlns="..." xmlns:x="http://yourapp.com">

例如:

<DnaLibrary RuntimeVersion="v4.0" Name="Ribbon Tests" Description="Ribbon Tests Description (not used)">
   <![CDATA[
     Imports System.Runtime.InteropServices
     Imports Microsoft.Office.Core
     Imports ExcelDna.Integration.CustomUI

     <ComVisible(True)> _
     Public Class MyRibbon
       Inherits ExcelRibbon

       Public Sub  OnButtonPressed(control as IRibbonControl)
           MsgBox("My Button Pressed on control " & control.Id,, "ExcelDna Ribbon!")
       End Sub

     End Class
   ]]>

  <CustomUI>
     <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
               xmlns:x="http://caioproiete.net">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group idQ="x:ORSErlang64" label="ORSErlang64">
              <button id="C1" label="Set Default" size="large"
                imageMso="StartAfterPrevious" onAction="OnButtonPressed" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
  </CustomUI>

</DnaLibrary>

enter image description here