Excel 2007加载项显示但不工作

Excel 2007加载项显示但不工作,excel,vba,add-in,Excel,Vba,Add In,我创建了一个显示在UI中的Excel加载项,但每次单击它都不起作用 Option Explicit Public sheetscol As Collection, depshtnm Public hasdeps As Boolean '*********************************** '*finds the external dependencies of the cell, and places them in the 'sheetscol' collection '*

我创建了一个显示在UI中的Excel加载项,但每次单击它都不起作用

Option Explicit

Public sheetscol As Collection, depshtnm
Public hasdeps As Boolean
'***********************************
'*finds the external dependencies of the cell, and places them in the 'sheetscol' collection
'***********************************
Sub depfinder_eventhandler(control As IRibbonControl)
    depfinder
End Sub
'--------------
Sub depfinder
 ...
End sub
这是XML自定义UI:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
  xmlns:m="MattSinSpace">
    <ribbon>
        <tabs>
            <tab idQ="m:MattTab" label="Matt Tools" insertAfterMso="TabHome">
                <group idQ="m:migration" label="migration tools">
                    <button idQ="m:DepFinderButton1" label="Highlight Dependencies" size="large"
                     onAction="depfinder_eventhandler"                         imageMso="HappyFace" />
        </group>
                <group idQ="m:RS1" visible = "false"/>
            <group idQ="m:RS2" visible = "false"/>
            </tab>
        </tabs>
    </ribbon>
</customUI>

我在制作外接程序方面相当业余,我一直在使用此页面来帮助我:


看起来一切都很好,在我的代码和UI中,唯一的区别是我包含了名称空间。

您的问题在于组和按钮的XML。您使用的是idQ,它是在外接程序之间共享控件时使用的限定符标识符。您希望在选项卡中使用此选项,因为您可以在外接程序之间共享选项卡,但不能在组或按钮之间共享。以下XML将起作用:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" xmlns:m="MattSinSpace">
<ribbon>
    <tabs>
        <tab idQ="m:MattTab" label="Matt Tools" insertAfterMso="TabHome">
                <group id="migration" label="migration tools">

        <button id="DepFinderButton1" label="Highlight Dependencies" size="large"
                 onAction="depfinder_eventhandler"  imageMso="HappyFace" />

        </group>

           <group id="RS1" visible = "false"/>
             <group id="RS2" visible = "false"/>
        </tab>
    </tabs>
</ribbon>


看看这是否有帮助?本页讨论按钮的各种属性,但您可以在总体文档中找到所需的所有内容。我发现XML非常易变,这是功能区的一个很好的资源:。如果你喜欢这个答案,你能接受吗:)